GCC Code Coverage Report


Directory: ./
File: sql/mysqld.cc
Date: 2022-11-26 14:12:44
Exec Total Coverage
Lines: 3245 3745 86.6%
Branches: 3363 7536 44.6%

Line Branch Exec Source
1 /* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /**
24 @file sql/mysqld.cc
25 MySQL server daemon.
26 */
27
28 /* clang-format off */
29 /**
30 @mainpage Welcome
31
32 Welcome to the MySQL source code documentation.
33
34 This documentation covers primarily the MySQL server,
35 for the @c mysqld process.
36
37 Other programs, like the MySQL Router, are also documented,
38 see the @ref PAGE_SERVER_TOOLS section.
39
40 The order chosen to present the content is to start with low level components,
41 and build upon previous sections, so that code is presented in a logical order.
42
43 For some sections, a full article (Doxygen 'page') presents the component in detail.
44
45 For other sections, only links are provided, as a starting point into the component.
46
47 For the user manual, see http://dev.mysql.com/doc/refman/8.0/en/
48
49 For the internals manual, see https://dev.mysql.com/doc/internals/en/index.html
50
51 This documentation is published for each release, starting with MySQL 8.0.
52
53 The present document corresponds to:
54
55 Document generated on: ${DOXYGEN_GENERATION_DATE},
56 branch: ${DOXYGEN_GENERATION_BRANCH},
57 revision: ${DOXYGEN_GENERATION_REVISION}
58
59 For the latest available version, see https://dev.mysql.com/doc/dev/mysql-server/latest/
60
61 For other versions, see https://dev.mysql.com/doc/index-archive.html
62 */
63
64 /**
65 @page PAGE_GET_STARTED Getting Started
66
67 - @ref start_source
68 - @subpage PAGE_CODING_GUIDELINES
69 - @ref start_debug
70
71 @section start_source Build from source
72
73 See https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
74
75 @section start_debug Debugging
76
77 The easiest way to install a server, and attach a debugger to it,
78 is to start the mysql-test-run (MTR) tool with debugging options
79
80 @verbatim
81 cd mysql-test
82 ./mtr --ddd main.parser
83 @endverbatim
84
85 The following functions are good candidates for breakpoints:
86 - #my_message_sql
87 - #dispatch_command
88
89 Replace 'main.parser' with another test script, or write your own, to debug a specific area.
90 */
91
92 /**
93 @page PAGE_CODING_GUIDELINES Coding Guidelines
94
95 This section shows the guidelines that MySQL developers
96 follow when writing new code.
97
98 New MySQL code uses the Google C++ coding style
99 (https://google.github.io/styleguide/cppguide.html), with two
100 exceptions:
101
102 - Member variable names: Do not use foo_. Instead, use
103 m_foo (non-static) or s_foo (static).
104
105 - Do not use non-const references as function parameters, even if they
106 are optional. Instead, use pointers for in/out and output parameters.
107 (This matches an older version of the Google style guide.) Do not use
108 references, whether const or non-const, as struct or class members.
109
110 Old projects and modifications to old code use an older MySQL-specific
111 style for the time being. Since 8.0, MySQL style uses the same formatting
112 rules as Google coding style (e.g., brace placement, indentation, line
113 lengths, etc.), but differs in a few important aspects:
114
115 - Class names: Do not use MyClass. Instead, use My_class.
116
117 - Function names: Use snake_case().
118
119 - Comment Style: Use either the // or <em>/</em>* *<em>/</em> syntax. // is
120 much more common but both syntaxes are permitted for the time being.
121
122 - Doxygen comments: Use <em>/</em>** ... *<em>/</em> syntax and not ///.
123
124 - Doxygen commands: Use '@' and not '\' for doxygen commands.
125
126 - You may see structs starting with st_ and being typedef-ed to some
127 UPPERCASE (e.g. typedef struct st_foo { ... } FOO). However,
128 this is legacy from when the codebase contained C. Do not make such new
129 typedefs nor structs with st_ prefixes, and feel free to remove those that
130 already exist, except in public header files that are part of libmysql
131 (which need to be parseable as C99).
132
133
134 Code formatting is enforced by use of clang-format throughout the code
135 base. However, note that formatting is only one part of coding style;
136 you are required to take care of non-formatting issues yourself, such as
137 following naming conventions, having clear ownership of code or minimizing
138 the use of macros. See the Google coding style guide for the entire list.
139
140 Consistent style is important for us, because everyone must know what to
141 expect. Knowing our rules, you'll find it easier to read our code, and when
142 you decide to contribute (which we hope you'll consider!) we'll find it
143 easier to read and review your code.
144
145 - @subpage GENERAL_DEVELOPMENT_GUIDELINES
146 - @subpage CPP_CODING_GUIDELINES_FOR_NDB_SE
147 - @subpage DBUG_TAGS
148
149 */
150
151 /**
152 @page PAGE_INFRASTRUCTURE Infrastructure
153
154 @section infra_basic Basic classes and templates
155
156 @subsection infra_basic_container Container
157
158 See #DYNAMIC_ARRAY, #List, #I_P_List, #LF_HASH.
159
160 @subsection infra_basic_syncho Synchronization
161
162 See #native_mutex_t, #native_rw_lock_t, #native_cond_t.
163
164 @subsection infra_basic_fileio File IO
165
166 See #my_open, #my_dir.
167
168 @section infra_server_blocks Server building blocks
169
170 @subsection infra_server_blocks_vio Virtual Input Output
171
172 See #Vio, #vio_init.
173
174 @section deployment Deployment
175
176 @subsection deploy_install Installation
177
178 See #opt_initialize, #bootstrap::run_bootstrap_thread.
179
180 @subsection deploy_startup Startup
181
182 See #mysqld_main.
183
184 @subsection deploy_shutdown Shutdown
185
186 See #handle_fatal_signal, #signal_hand.
187
188 @subsection deploy_upgrade Upgrade
189
190 See #Mysql::Tools::Upgrade::Program.
191
192 */
193
194 /**
195 @page PAGE_PROTOCOL Client/Server Protocol
196
197 @section protocol_overview Overview
198
199 The MySQL protocol is used between MySQL Clients and a MySQL Server.
200 It is implemented by:
201 - Connectors (Connector/C, Connector/J, and so forth)
202 - MySQL Proxy
203 - Communication between master and slave replication servers
204
205 The protocol supports these features:
206 - Transparent encryption using SSL
207 - Transparent compression
208 - A @ref page_protocol_connection_phase where capabilities and
209 authentication data are exchanged
210 - A @ref page_protocol_command_phase which accepts commands
211 from the client and executes them
212
213 Further reading:
214 - @subpage page_protocol_basics
215 - @subpage page_protocol_connection_lifecycle
216 */
217
218 /** @page page_mysqlx_protocol X %Protocol
219
220 @par Topics in this section:
221
222 - @subpage mysqlx_protocol_lifecycle
223 - @subpage mysqlx_protocol_authentication
224 - @subpage mysqlx_protocol_messages
225 - @subpage mysqlx_protocol_expectations
226 - @subpage mysqlx_protocol_notices
227 - @subpage mysqlx_protocol_xplugin
228 - @subpage mysqlx_protocol_use_cases
229 - @subpage mysqlx_protocol_implementation
230 - @subpage mysqlx_protocol_comparison
231 - @subpage mysqlx_community_connector
232
233 The X %Protocol is implemented by the X Plugin and the following
234 MySQL clients support the protocol:
235
236 - MYSQLXSHELL
237
238 - MySQL for Visual Studio 2.0.2 or higher
239
240 - MySQL Connector/J 6.0.2 or higher
241
242 - MySQL Connector/Net 7.0.2 or higher
243
244 - MySQL Connector/Node.js
245 */
246
247
248 /**
249 @page PAGE_SQL_EXECUTION SQL Query Execution
250
251 @section sql_query_exec_parsing SQL Parsing
252
253 The parser processes SQL strings and builds a tree representation of them.
254
255 See @ref GROUP_PARSER.
256
257 @subpage PAGE_SQL_Optimizer
258
259 @subpage stored_programs
260
261 @section sql_query_exec_prepared Prepared statements
262
263 See #mysql_stmt_prepare
264
265 @section func_stored_proc Stored procedures
266
267 See #sp_head, #sp_instr.
268
269 @section sql_query_exec_sql_functions SQL Functions
270
271 See #Item_func
272
273 @section sql_query_exec_error_handling Error handling
274
275 See #my_message, #my_error
276
277 @subpage PAGE_TXN
278
279 */
280
281 /**
282 @page PAGE_STORAGE Data Storage
283
284 @section storage_innodb Innodb
285
286 See #ha_innobase or read details about InnoDB internals:
287 - @subpage PAGE_INNODB_PFS
288 - @subpage PAGE_INNODB_REDO_LOG
289 - @subpage PAGE_INNODB_LOCK_SYS
290 - @subpage PAGE_INNODB_UTILS
291
292 @section storage_temptable Temp table
293
294 Before 8.0, temporary tables were handled by heap engine.
295 The heap engine had no feature to store bigger tables on disk.
296
297 Since 8.0, there is a brand new temptable engine, which
298 is written from scratch using c++11. It has following advantages:
299 - it is able to store bigger tables on disk (in temporary files),
300 - it uses row format with variable size (can save memory for varchars),
301 - it is better designed (easier to maintain).
302
303 @subpage PAGE_TEMPTABLE
304
305 */
306
307
308 /**
309 @page PAGE_REPLICATION Replication
310
311 @subpage PAGE_RPL_FIELD_METADATA
312
313 */
314
315 /**
316 @page PAGE_TXN Transactions
317
318 See #trans_begin, #trans_commit, #trans_rollback.
319 */
320
321 /**
322 @page PAGE_SECURITY Security
323
324 @subpage AUTHORIZATION_PAGE
325 @subpage PAGE_KEYRING_COMPONENT
326 */
327
328
329 /**
330 @page PAGE_MONITORING Monitoring
331
332 @subpage PAGE_PFS
333 */
334
335 /**
336 @page PAGE_EXTENDING Extending MySQL
337
338 Components
339 ----------
340
341 MySQL 8.0 introduces support for extending the server through components.
342 Components can communicate with other components through service APIs.
343 And can provide implementations of service APIs for other components to use.
344 All components are equal and can communicate with all other components.
345 Service implementations can be found by name via a registry service handle
346 which is passed to the component initialization function.
347 There can be multiple service API implementations for a single service API.
348 One of them is the default implementation.
349 Service API are stateless by definition. If they need to handle state or
350 object instances they need to do so by using factory methods and instance
351 handles.
352
353 To ease up transition to the component model the current server
354 functionality (server proper and plugins) is contained within
355 a dedicated built in server component. The server component currently
356 contains all of the functionality provided by the server and
357 classical server plugins.
358
359 More components can be installed via the "INSTALL COMPONENT" SQL command.
360
361 The component infrastructure is designed as a replacement for the classical
362 MySQL plugin system as it does not suffer from some of the limitations of it
363 and provides better isolation for the component code.
364
365 See @subpage PAGE_COMPONENTS.
366
367 Plugins and Services
368 --------------------
369
370 As of MySQL 5.1 the server functionality can be extended through
371 installing (dynamically or statically linked) extra code modules
372 called plugins.
373
374 The server defines a set of well known plugin APIs that the modules
375 can implement.
376
377 To allow plugins to reuse server code the server exposes a pre-defined
378 set of functions to plugins called plugin services.
379
380 See the following for more details:
381 - @subpage page_ext_plugins
382 - @subpage page_ext_plugin_services
383
384
385 User Defined Functions
386 ----------------------
387
388 Native code user defined functions can be added to MySQL server using
389 the CREATE FUNCTION ... SONAME syntax.
390
391 These can co-exit with @ref page_ext_plugins or reside in their own
392 separate binaries.
393
394 To learn how to create these user defined functions see @subpage page_ext_udf
395 */
396
397
398 /**
399 @page PAGE_SERVICES Available services
400
401 @subpage PAGE_TABLE_ACCESS_SERVICE
402 */
403
404
405 /**
406 @page PAGE_SERVER_TOOLS Server tools
407
408 - @subpage PAGE_MYSQL_ROUTER
409 */
410
411
412 /**
413 @page PAGE_CLIENT_TOOLS Client tools
414
415 See mysqldump.cc mysql.cc
416 */
417
418
419 /**
420 @page PAGE_TESTING_TOOLS Testing Tools
421
422 - @subpage PAGE_MYSQL_TEST_RUN
423 */
424
425 /**
426 @page PAGE_DEV_TOOLS Development Tools
427
428 - @subpage PAGE_LOCK_ORDER
429 */
430
431 /**
432 @page PAGE_CODE_PATHS Code paths
433
434 This section details how the server executes some statements,
435 to illustrate how different parts work together.
436
437 Note that this overall view might take some shortcuts,
438 hiding some details or taking liberties with the notations,
439 to present the whole code structure in a comprehensible way.
440
441 - @subpage CODE_PATH_CREATE_TABLE
442 */
443
444 /**
445 @page CODE_PATH_CREATE_TABLE CREATE TABLE
446
447 @section CREATE_TABLE_PARSER Parser
448
449 @startuml
450
451 actor ddl as "CREATE TABLE Query"
452 participant server as "MySQL Server"
453 participant parser as "SQL Parser"
454 participant bison as "Bison Parser"
455 participant lexer as "Lexical Scanner"
456 participant pt as "Parse Tree Nodes"
457
458 ddl -> server : DDL QUERY TEXT
459 server -> parser : THD::sql_parser()
460 == Bison parser ==
461 parser -> bison : MYSQLparse()
462 bison -> lexer : MYSQLlex()
463 bison <-- lexer : yylval, yylloc
464 bison -> pt : new
465 activate pt
466 parser <-- pt : Abstract Syntax Tree
467
468 @enduml
469
470 When a query is sent to the server,
471 the first step is to invoke the bison parser
472 to build an Abstract Syntax Tree to represent the query text.
473
474 Assume the following statement:
475 @verbatim
476 CREATE TABLE test.t1 (a int) ENGINE = "INNODB";
477 @endverbatim
478
479 In the bison grammar file, the rule implementing the CREATE TABLE
480 statement is @c create_table_stmt.
481
482 The tree created is an object of class @ref PT_create_table_stmt.
483
484 This parse tree node has several related nodes, such as:
485 - @ref PT_create_table_option and sub classes, for table options.
486 - @ref PT_table_element and sub classes, for the columns, indexes, etc.
487
488 The collection of nodes returned after the bison parsing is known
489 as the "Abstract Syntax Tree" that represents a SQL query.
490
491 @section CREATE_TABLE_CMD Sql command
492
493 @startuml
494
495 actor ddl as "CREATE TABLE Query"
496 participant server as "MySQL Server"
497 participant parser as "SQL Parser"
498 participant ast as "Abstract Syntax Tree"
499 participant cmd as "SQL Command"
500 participant ci as "HA_CREATE_INFO"
501 participant plugin as "MySQL plugin"
502
503 ddl -> server : DDL QUERY TEXT
504 server -> parser : THD::sql_parser()
505 == Bison parser ==
506 == Build SQL command ==
507 parser -> ast : make_cmd()
508 ast -> ast : contextualize()
509 ast -> ci : build()
510 activate ci
511 ci -> plugin : ha_resolve_engine()
512 ci <-- plugin : storage engine handlerton
513 ast <-- ci : Parse Tree (contextualized)
514 ast -> cmd : build()
515 activate cmd
516 server <-- cmd : SQL Command
517
518 @enduml
519
520 Once the bison parser has finished parsing a query text,
521 the next step is to build a SQL command from the Abstract Syntax Tree.
522
523 In the Abstract Syntax Tree, attributes like a storage engine name
524 ("INNODB") are represented as strings, taken from the query text.
525
526 These attributes need to be converted to objects in the SQL context,
527 such as an @ref innodb_hton pointer to represent the INNODB storage engine.
528
529 The process that performs these transformations is contextualize().
530
531 The @ref Parse_tree_root class is an abstract factory, building @ref Sql_cmd
532 objects.
533
534 For a CREATE TABLE statement, class @ref PT_create_table_stmt builds a
535 concrete @ref Sql_cmd_create_table object.
536
537 @ref PT_create_table_stmt::make_cmd() in particular performs the following
538 actions:
539 - contextualize the parse tree for the CREATE TABLE statement.
540 - build a @ref HA_CREATE_INFO structure to represent the table DDL.
541 - resolve the storage engine name to an actual @ref handlerton pointer,
542 in @ref PT_create_table_engine_option::contextualize()
543
544 @section CREATE_TABLE_RUNTIME Runtime execution
545
546 @startuml
547
548 actor ddl as "CREATE TABLE Query"
549 participant server as "MySQL Server"
550 participant cmd as "SQL Command"
551 participant rt as "Runtime"
552
553 ddl -> server : DDL QUERY TEXT
554 == Bison parser ==
555 == Build SQL command ==
556 == Execute SQL command ==
557 server -> cmd : execute()
558 cmd -> rt : mysql_create_table()
559
560 @enduml
561
562 Execution of a CREATE TABLE statement invokes
563 @ref Sql_cmd_create_table::execute(),
564 which in turns calls:
565 - @ref mysql_create_table(),
566 - @ref mysql_create_table_no_lock(),
567 - @ref create_table_impl(),
568 - @ref rea_create_base_table().
569
570 Execution of this code is the runtime implementation of the CREATE TABLE
571 statement, and eventually leads to:
572 - @ref dd::create_table(), to create the table in the Data Dictionary,
573 - @ref ha_create_table(), to create the table in the handlerton.
574
575 Details about the dictionary and the storage engine are expanded
576 in the following two sections.
577
578
579 @section CREATE_TABLE_DD Data Dictionary
580
581 @startuml
582
583 actor ddl as "CREATE TABLE Query"
584 participant server as "MySQL Server"
585 participant rt as "Runtime"
586 participant dd as "Data Dictionary"
587 participant ddt as "Data Dictionary Table"
588 participant sdi as "Serialized Dictionary Information"
589 participant hton as "Handlerton"
590 participant se as "Storage Engine"
591 participant ts as "Tablespace"
592
593 ddl -> server : DDL QUERY TEXT
594 == ... ==
595 server -> rt : ( execution code path )
596 == Data Dictionary ==
597 rt -> dd : dd::create_table()
598 dd -> ddt : build dd::Table()
599 activate ddt
600 rt <-- ddt : dd:Table instance
601 == Serialized Dictionary Information ==
602 rt -> dd : store()
603 dd -> sdi : dd::sdi::store()
604 sdi -> sdi : sdi_tablespace::store_tbl_sdi()
605 == Storage Engine (Tablespace) ==
606 sdi -> hton : handlerton::sdi()
607 hton -> se : ::sdi() implementation.
608 se -> ts : write metadata in tablespace
609
610 @enduml
611
612 In the data dictionary, creation of a new table calls:
613 - @ref dd::create_dd_user_table()
614 - @ref fill_dd_table_from_create_info()
615
616 The data dictionary code parses the content of the HA_CREATE_INFO
617 input, and builds a @ref dd::Table object, to represent the table metadata.
618 Part of this metadata includes the storage engine name.
619
620 The runtime code then calls @c store() to save this new metadata.
621
622 To store a table metadata, the data dictionary code first serialize it
623 into an sdi format.
624
625 The serialized object is then stored in persistence,
626 either in a tablespace or in a file:
627 - @ref sdi_tablespace::store_tbl_sdi()
628 - @ref sfi_file::store_tbl_sdi()
629
630 When storing data into a tablespace, the storage engine handlerton is
631 invoked, so that the storage engine can ultimately store
632 the table metadata in the tablespace maintained by the storage engine.
633
634 @section CREATE_TABLE_SE Storage Engine
635
636 @startuml
637
638 actor ddl as "CREATE TABLE Query"
639 participant server as "MySQL Server"
640 participant rt as "Runtime"
641 participant sei as "Storage Engine Interface"
642 participant hton as "Storage Engine Handlerton"
643 participant handler as "Storage Engine Handler"
644
645 ddl -> server : DDL QUERY TEXT
646 == ... ==
647 server -> rt : ( execution code path )
648 == Storage Engine (table) ==
649 rt -> sei : ha_create_table()
650 sei -> hton : handlerton::create()
651 hton -> handler : (build a new table handler)
652 activate handler
653 sei <-- handler : storage engine table handler
654 sei -> handler : handler::create()
655
656 @enduml
657
658 When execution of the CREATE TABLE statement
659 reaches the storage engine interface,
660 the SQL layer function @ref ha_create_table()
661 invokes the storage engine @ref handlerton::create()
662 method to instantiate a new storage engine table,
663 represented by @ref handler.
664 The SQL layer then calls @ref handler::create() to create
665 the table inside the storage engine.
666 */
667
668 /**
669 @page PAGE_SQL_Optimizer SQL Optimizer
670
671 The task of query optimizer is to determine the most efficient means for
672 executing queries. The query optimizer consists of the following
673 sub-modules:
674
675 - @ref Query_Resolver
676 - @ref Query_Optimizer
677 - @ref Query_Planner
678 - @ref Query_Executor
679
680 @subpage PAGE_OPT_TRACE
681
682 Additional articles about the query optimizer:
683
684 - @ref PAGE_OPT_TRACE
685 - @ref AGGREGATE_CHECKS
686 */
687 /* clang-format on */
688
689 #include "sql/mysqld.h"
690
691 #include "my_config.h"
692
693 #include "errmsg.h" // init_client_errs
694 #include "ft_global.h"
695 #ifdef _WIN32
696 #include "jemalloc_win.h"
697 #endif
698 #include "keycache.h" // KEY_CACHE
699 #include "libbinlogevents/include/binlog_event.h"
700 #include "libbinlogevents/include/control_events.h"
701 #include "m_string.h"
702 #include "migrate_keyring.h" // Migrate_keyring
703 #include "my_alloc.h"
704 #include "my_base.h"
705 #include "my_bitmap.h" // MY_BITMAP
706 #include "my_command.h"
707 #include "my_compiler.h"
708 #include "my_dbug.h"
709 #include "my_default.h" // print_defaults
710 #include "my_dir.h"
711 #include "my_getpwnam.h"
712 #include "my_loglevel.h"
713 #include "my_macros.h"
714 #include "my_shm_defaults.h" // IWYU pragma: keep
715 #include "my_stacktrace.h" // my_set_exception_pointers
716 #include "my_thread_local.h"
717 #include "my_time.h"
718 #include "my_timer.h" // my_timer_initialize
719 #include "myisam.h"
720 #include "mysql/components/services/bits/psi_bits.h"
721 #include "mysql/components/services/log_builtins.h"
722 #include "mysql/components/services/log_shared.h"
723 #include "mysql/components/services/mysql_runtime_error_service.h"
724 #include "mysql/plugin.h"
725 #include "mysql/plugin_audit.h"
726 #include "mysql/psi/mysql_cond.h"
727 #include "mysql/psi/mysql_file.h"
728 #include "mysql/psi/mysql_memory.h" // mysql_memory_init
729 #include "mysql/psi/mysql_mutex.h"
730 #include "mysql/psi/mysql_rwlock.h"
731 #include "mysql/psi/mysql_socket.h"
732 #include "mysql/psi/mysql_stage.h"
733 #include "mysql/psi/mysql_statement.h"
734 #include "mysql/psi/mysql_thread.h"
735 #include "mysql/psi/psi_cond.h"
736 #include "mysql/psi/psi_data_lock.h"
737 #include "mysql/psi/psi_error.h"
738 #include "mysql/psi/psi_file.h"
739 #include "mysql/psi/psi_idle.h"
740 #include "mysql/psi/psi_mdl.h"
741 #include "mysql/psi/psi_memory.h"
742 #include "mysql/psi/psi_mutex.h"
743 #include "mysql/psi/psi_rwlock.h"
744 #include "mysql/psi/psi_socket.h"
745 #include "mysql/psi/psi_stage.h"
746 #include "mysql/psi/psi_statement.h"
747 #include "mysql/psi/psi_system.h"
748 #include "mysql/psi/psi_table.h"
749 #include "mysql/psi/psi_thread.h"
750 #include "mysql/psi/psi_tls_channel.h"
751 #include "mysql/psi/psi_transaction.h"
752 #include "mysql/service_mysql_alloc.h"
753 #include "mysql/thread_type.h"
754 #include "mysql_com.h"
755 #include "mysql_time.h"
756 #include "mysql_version.h"
757 #include "mysqld_error.h"
758 #include "mysys/buffered_error_log.h"
759 #include "mysys_err.h" // EXIT_OUT_OF_MEMORY
760 #include "pfs_thread_provider.h"
761 #include "print_version.h"
762 #include "scope_guard.h" // create_scope_guard()
763 #include "server_component/log_sink_buffer.h" // log_error_stage_set()
764 #include "server_component/log_sink_perfschema.h" // log_error_read_log()
765 #ifdef _WIN32
766 #include <shellapi.h>
767 #endif
768 #include "sql/auth/auth_common.h" // grant_init
769 #include "sql/auth/sql_authentication.h" // init_rsa_keys
770 #include "sql/auth/sql_security_ctx.h"
771 #include "sql/auto_thd.h" // Auto_THD
772 #include "sql/binlog.h" // mysql_bin_log
773 #include "sql/bootstrap.h" // bootstrap
774 #include "sql/check_stack.h"
775 #include "sql/conn_handler/connection_acceptor.h" // Connection_acceptor
776 #include "sql/conn_handler/connection_handler_impl.h" // Per_thread_connection_handler
777 #include "sql/conn_handler/connection_handler_manager.h" // Connection_handler_manager
778 #include "sql/conn_handler/socket_connection.h" // stmt_info_new_packet
779 #include "sql/current_thd.h" // current_thd
780 #include "sql/dd/cache/dictionary_client.h"
781 #include "sql/debug_sync.h" // debug_sync_end
782 #include "sql/derror.h"
783 #include "sql/event_data_objects.h" // init_scheduler_psi_keys
784 #include "sql/events.h" // Events
785 #include "sql/handler.h"
786 #include "sql/hostname_cache.h" // hostname_cache_init
787 #include "sql/init.h" // unireg_init
788 #include "sql/item.h"
789 #include "sql/item_cmpfunc.h" // Arg_comparator
790 #include "sql/item_create.h"
791 #include "sql/item_func.h"
792 #include "sql/item_strfunc.h" // Item_func_uuid
793 #include "sql/keycaches.h" // get_or_create_key_cache
794 #include "sql/log.h"
795 #include "sql/log_event.h" // Rows_log_event
796 #include "sql/log_resource.h"
797 #include "sql/mdl.h"
798 #include "sql/mdl_context_backup.h" // mdl_context_backup_manager
799 #include "sql/my_decimal.h"
800 #include "sql/mysqld_daemon.h"
801 #include "sql/mysqld_thd_manager.h" // Global_THD_manager
802 #include "sql/opt_costconstantcache.h" // delete_optimizer_cost_module
803 #include "sql/range_optimizer/range_optimizer.h" // range_optimizer_init
804 #include "sql/options_mysqld.h" // OPT_THREAD_CACHE_SIZE
805 #include "sql/partitioning/partition_handler.h" // partitioning_init
806 #include "sql/persisted_variable.h" // Persisted_variables_cache
807 #include "sql/plugin_table.h"
808 #include "sql/protocol.h"
809 #include "sql/psi_memory_key.h" // key_memory_MYSQL_RELAY_LOG_index
810 #include "sql/query_options.h"
811 #include "sql/replication.h" // thd_enter_cond
812 #include "sql/resourcegroups/resource_group_mgr.h" // init, post_init
813 #include "sql/sql_profile.h"
814 #ifdef _WIN32
815 #include "sql/restart_monitor_win.h"
816 #endif
817 #include "sql/rpl_async_conn_failover_configuration_propagation.h"
818 #include "sql/rpl_event_ctx.h" // Rpl_event_ctx
819 #include "sql/rpl_filter.h"
820 #include "sql/rpl_gtid.h"
821 #include "sql/rpl_gtid_persist.h" // Gtid_table_persistor
822 #include "sql/rpl_handler.h" // RUN_HOOK
823 #include "sql/rpl_info_factory.h"
824 #include "sql/rpl_info_handler.h"
825 #include "sql/rpl_injector.h" // injector
826 #include "sql/rpl_io_monitor.h"
827 #include "sql/rpl_log_encryption.h"
828 #include "sql/rpl_source.h" // max_binlog_dump_events
829 #include "sql/rpl_mi.h"
830 #include "sql/rpl_msr.h" // Multisource_info
831 #include "sql/rpl_rli.h" // Relay_log_info
832 #include "sql/rpl_replica.h" // replica_load_tmpdir
833 #include "sql/rpl_trx_tracking.h"
834 #include "sql/sd_notify.h" // sd_notify_connect
835 #include "sql/session_tracker.h"
836 #include "sql/set_var.h"
837 #include "sql/sp_head.h" // init_sp_psi_keys
838 #include "sql/sql_audit.h" // mysql_audit_general
839 #include "sql/sql_base.h"
840 #include "sql/sql_callback.h" // MUSQL_CALLBACK
841 #include "sql/sql_class.h" // THD
842 #include "sql/sql_component.h"
843 #include "sql/sql_connect.h"
844 #include "sql/sql_error.h"
845 #include "sql/sql_initialize.h" // opt_initialize_insecure
846 #include "sql/sql_lex.h"
847 #include "sql/sql_list.h"
848 #include "sql/sql_locale.h" // MY_LOCALE
849 #include "sql/sql_manager.h" // start_handle_manager
850 #include "sql/sql_parse.h" // check_stack_overrun
851 #include "sql/sql_plugin.h" // opt_plugin_dir
852 #include "sql/sql_plugin_ref.h"
853 #include "sql/sql_reload.h" // handle_reload_request
854 #include "sql/sql_restart_server.h" // is_mysqld_managed
855 #include "sql/sql_servers.h"
856 #include "sql/sql_show.h"
857 #include "sql/sql_table.h" // build_table_filename
858 #include "sql/sql_udf.h"
859 #include "sql/ssl_acceptor_context_iterator.h"
860 #include "sql/ssl_acceptor_context_operator.h"
861 #include "sql/ssl_acceptor_context_status.h"
862 #include "sql/ssl_init_callback.h"
863 #include "sql/sys_vars.h" // fixup_enforce_gtid_consistency_...
864 #include "sql/sys_vars_shared.h" // intern_find_sys_var
865 #include "sql/table_cache.h" // table_cache_manager
866 #include "sql/tc_log.h" // tc_log
867 #include "sql/thd_raii.h"
868 #include "sql/thr_malloc.h"
869 #include "sql/threadpool.h"
870 #include "sql/transaction.h"
871 #include "sql/tztime.h" // Time_zone
872 #include "sql/udf_service_impl.h"
873 #include "sql/xa.h"
874 #include "sql/xa/transaction_cache.h" // xa::Transaction_cache
875 #include "sql_common.h" // mysql_client_plugin_init
876 #include "sql_string.h"
877 #include "storage/myisam/ha_myisam.h" // HA_RECOVER_OFF
878 #include "storage/perfschema/pfs_services.h"
879 #include "thr_lock.h"
880 #include "thr_mutex.h"
881 #include "typelib.h"
882 #include "violite.h"
883 #include "my_openssl_fips.h" // OPENSSL_ERROR_LENGTH, set_fips_mode
884
885 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
886 #include "storage/perfschema/pfs_server.h"
887 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
888
889 #ifdef _WIN32
890 #include "sql/conn_handler/named_pipe_connection.h"
891 #include "sql/conn_handler/shared_memory_connection.h"
892 #include "sql/named_pipe.h"
893 #endif
894
895 #ifdef HAVE_ARPA_INET_H
896 #include <arpa/inet.h>
897 #endif
898 #ifdef MY_MSCRT_DEBUG
899 #include <crtdbg.h>
900 #endif
901 #include <errno.h>
902 #include <fcntl.h>
903 #include <fenv.h>
904 #include <limits.h>
905 #ifdef HAVE_GRP_H
906 #include <grp.h>
907 #endif
908 #ifndef _WIN32
909 #include <netdb.h>
910 #endif
911 #ifdef HAVE_NETINET_IN_H
912 #include <netinet/in.h>
913 #endif
914 #include <signal.h>
915 #include <stdarg.h>
916 #include <stddef.h>
917 #include <stdio.h>
918 #include <stdlib.h>
919 #include <string.h>
920 #include <sys/types.h>
921 #ifdef HAVE_SYS_MMAN_H
922 #include <sys/mman.h>
923 #endif
924 #ifdef HAVE_SYS_PRCTL_H
925 #include <sys/prctl.h>
926 #endif
927 #ifdef HAVE_SYS_RESOURCE_H
928 #include <sys/resource.h>
929 #endif
930 #include <sys/stat.h>
931 #ifdef HAVE_UNISTD_H
932 #include <unistd.h>
933 #endif
934 #ifdef _WIN32
935 #include <crtdbg.h>
936 #include <process.h>
937 #endif
938 #include "unicode/putil.h" // u_setDataDirectory()
939 #include "unicode/uclean.h" // u_cleanup()
940
941 #include <algorithm>
942 #include <atomic>
943 #include <functional>
944 #include <new>
945
946 #ifndef EMBEDDED_LIBRARY
947 #ifdef WITH_LOCK_ORDER
948 #include "sql/debug_lock_order.h"
949 #endif /* WITH_LOCK_ORDER */
950 #endif /* EMBEDDED_LIBRARY */
951
952 #ifndef EMBEDDED_LIBRARY
953 #include "srv_session.h"
954 #endif
955
956 #include <mysql/components/minimal_chassis.h>
957 #include <mysql/components/services/dynamic_loader_scheme_file.h>
958 #include <mysql/components/services/mysql_psi_system_service.h>
959 #include <mysql/components/services/mysql_rwlock_service.h>
960 #include <mysql/components/services/ongoing_transaction_query_service.h>
961 #include "sql/auth/dynamic_privileges_impl.h"
962 #include "sql/dd/dd.h" // dd::shutdown
963 #include "sql/dd/dd_kill_immunizer.h" // dd::DD_kill_immunizer
964 #include "sql/dd/dictionary.h" // dd::get_dictionary
965 #include "sql/dd/ndbinfo_schema/init.h" // dd::ndbinfo::init_schema_and_tables()
966 #include "sql/dd/performance_schema/init.h" // performance_schema::init
967 #include "sql/dd/upgrade/server.h" // dd::upgrade::upgrade_system_schemas
968 #include "sql/dd/upgrade_57/upgrade.h" // dd::upgrade_57::in_progress
969 #include "sql/server_component/component_sys_var_service_imp.h"
970 #include "sql/server_component/log_builtins_filter_imp.h"
971 #include "sql/server_component/log_builtins_imp.h"
972 #include "sql/server_component/mysql_server_keyring_lockable_imp.h"
973 #include "sql/server_component/persistent_dynamic_loader_imp.h"
974 #include "sql/srv_session.h"
975
976 using std::max;
977 using std::min;
978 using std::vector;
979
980 #define mysqld_charset &my_charset_latin1
981 #define mysqld_default_locale_name "en_US"
982
983 #ifdef HAVE_FPU_CONTROL_H
984 #include <fpu_control.h> // IWYU pragma: keep
985 #elif defined(__i386__)
986 #define fpu_control_t unsigned int
987 #define _FPU_EXTENDED 0x300
988 #define _FPU_DOUBLE 0x200
989 #if defined(__GNUC__)
990 #define _FPU_GETCW(cw) asm volatile("fnstcw %0" : "=m"(*&cw))
991 #define _FPU_SETCW(cw) asm volatile("fldcw %0" : : "m"(*&cw))
992 #else
993 #define _FPU_GETCW(cw) (cw = 0)
994 #define _FPU_SETCW(cw)
995 #endif
996 #endif
997 12058 inline void setup_fpu() {
998 #ifdef HAVE_FEDISABLEEXCEPT
999 12058 fedisableexcept(FE_ALL_EXCEPT);
1000 #endif
1001
1002 /* Set FPU rounding mode to "round-to-nearest" */
1003 12058 fesetround(FE_TONEAREST);
1004
1005 /*
1006 x86 (32-bit) requires FPU precision to be explicitly set to 64 bit
1007 (double precision) for portable results of floating point operations.
1008 However, there is no need to do so if compiler is using SSE2 for floating
1009 point, double values will be stored and processed in 64 bits anyway.
1010 */
1011 #if defined(__i386__) && !defined(__SSE2_MATH__)
1012 #if !defined(_WIN32)
1013 fpu_control_t cw;
1014 _FPU_GETCW(cw);
1015 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
1016 _FPU_SETCW(cw);
1017 #endif /* _WIN32 && */
1018 #endif /* __i386__ */
1019 12058 }
1020
1021 extern "C" void handle_fatal_signal(int sig);
1022 void my_server_abort();
1023
1024 /* Constants */
1025
1026 #include "welcome_copyright_notice.h" // ORACLE_WELCOME_COPYRIGHT_NOTICE
1027
1028 const char *show_comp_option_name[] = {"YES", "NO", "DISABLED"};
1029
1030 static const char *tc_heuristic_recover_names[] = {"OFF", "COMMIT", "ROLLBACK",
1031 NullS};
1032 static TYPELIB tc_heuristic_recover_typelib = {
1033 array_elements(tc_heuristic_recover_names) - 1, "",
1034 tc_heuristic_recover_names, nullptr};
1035
1036 const char *first_keyword = "first", *binary_keyword = "BINARY";
1037 const char *my_localhost = "localhost";
1038
1039 bool opt_large_files = sizeof(my_off_t) > 4;
1040 static bool opt_autocommit; ///< for --autocommit command-line option
1041 static get_opt_arg_source source_autocommit;
1042
1043 /*
1044 Used with --help for detailed option
1045 */
1046 bool opt_help = false, opt_verbose = false, opt_validate_config = false;
1047
1048 arg_cmp_func Arg_comparator::comparator_matrix[5] = {
1049 &Arg_comparator::compare_string, // Compare strings
1050 &Arg_comparator::compare_real, // Compare float values
1051 &Arg_comparator::compare_int_signed, // Compare signed int values
1052 &Arg_comparator::compare_row, // Compare row values
1053 &Arg_comparator::compare_decimal}; // Compare decimal values
1054
1055 PSI_file_key key_file_binlog_cache;
1056 PSI_file_key key_file_binlog_index_cache;
1057
1058 #ifdef HAVE_PSI_INTERFACE
1059 static PSI_mutex_key key_LOCK_status;
1060 static PSI_mutex_key key_LOCK_manager;
1061 static PSI_mutex_key key_LOCK_crypt;
1062 static PSI_mutex_key key_LOCK_user_conn;
1063 static PSI_mutex_key key_LOCK_global_system_variables;
1064 static PSI_mutex_key key_LOCK_prepared_stmt_count;
1065 static PSI_mutex_key key_LOCK_replica_list;
1066 static PSI_mutex_key key_LOCK_sql_replica_skip_counter;
1067 static PSI_mutex_key key_LOCK_replica_net_timeout;
1068 static PSI_mutex_key key_LOCK_replica_trans_dep_tracker;
1069 static PSI_mutex_key key_LOCK_uuid_generator;
1070 static PSI_mutex_key key_LOCK_error_messages;
1071 static PSI_mutex_key key_LOCK_default_password_lifetime;
1072 static PSI_mutex_key key_LOCK_mandatory_roles;
1073 static PSI_mutex_key key_LOCK_password_history;
1074 static PSI_mutex_key key_LOCK_password_reuse_interval;
1075 static PSI_mutex_key key_LOCK_sql_rand;
1076 static PSI_mutex_key key_LOCK_log_throttle_qni;
1077 static PSI_mutex_key key_LOCK_reset_gtid_table;
1078 static PSI_mutex_key key_LOCK_compress_gtid_table;
1079 static PSI_mutex_key key_LOCK_collect_instance_log;
1080 static PSI_mutex_key key_BINLOG_LOCK_commit;
1081 static PSI_mutex_key key_BINLOG_LOCK_commit_queue;
1082 static PSI_mutex_key key_BINLOG_LOCK_done;
1083 static PSI_mutex_key key_BINLOG_LOCK_flush_queue;
1084 static PSI_mutex_key key_BINLOG_LOCK_index;
1085 static PSI_mutex_key key_BINLOG_LOCK_log;
1086 static PSI_mutex_key key_BINLOG_LOCK_binlog_end_pos;
1087 static PSI_mutex_key key_BINLOG_LOCK_sync;
1088 static PSI_mutex_key key_BINLOG_LOCK_sync_queue;
1089 static PSI_mutex_key key_BINLOG_LOCK_xids;
1090 static PSI_rwlock_key key_rwlock_global_sid_lock;
1091 PSI_rwlock_key key_rwlock_gtid_mode_lock;
1092 static PSI_rwlock_key key_rwlock_LOCK_system_variables_hash;
1093 static PSI_rwlock_key key_rwlock_LOCK_sys_init_connect;
1094 static PSI_rwlock_key key_rwlock_LOCK_sys_init_replica;
1095 static PSI_cond_key key_BINLOG_COND_done;
1096 static PSI_cond_key key_BINLOG_COND_flush_queue;
1097 static PSI_cond_key key_BINLOG_update_cond;
1098 static PSI_cond_key key_BINLOG_prep_xids_cond;
1099 static PSI_cond_key key_COND_manager;
1100 static PSI_cond_key key_COND_compress_gtid_table;
1101 static PSI_thread_key key_thread_signal_hand;
1102 static PSI_thread_key key_thread_main;
1103 static PSI_file_key key_file_casetest;
1104 static PSI_file_key key_file_pid;
1105 #if defined(_WIN32)
1106 static PSI_thread_key key_thread_handle_con_namedpipes;
1107 static PSI_thread_key key_thread_handle_con_sharedmem;
1108 static PSI_thread_key key_thread_handle_con_sockets;
1109 static PSI_mutex_key key_LOCK_handler_count;
1110 static PSI_cond_key key_COND_handler_count;
1111 static PSI_thread_key key_thread_handle_shutdown_restart;
1112 static PSI_rwlock_key key_rwlock_LOCK_named_pipe_full_access_group;
1113 #else
1114 static PSI_mutex_key key_LOCK_socket_listener_active;
1115 static PSI_cond_key key_COND_socket_listener_active;
1116 static PSI_mutex_key key_LOCK_start_signal_handler;
1117 static PSI_cond_key key_COND_start_signal_handler;
1118 #endif // _WIN32
1119 static PSI_mutex_key key_LOCK_server_started;
1120 static PSI_cond_key key_COND_server_started;
1121 static PSI_mutex_key key_LOCK_keyring_operations;
1122 static PSI_mutex_key key_LOCK_tls_ctx_options;
1123 static PSI_mutex_key key_LOCK_admin_tls_ctx_options;
1124 static PSI_mutex_key key_LOCK_rotate_binlog_master_key;
1125 static PSI_mutex_key key_LOCK_partial_revokes;
1126 static PSI_mutex_key key_LOCK_authentication_policy;
1127 static PSI_mutex_key key_LOCK_global_conn_mem_limit;
1128 #endif /* HAVE_PSI_INTERFACE */
1129
1130 /**
1131 Statement instrumentation key for replication.
1132 */
1133 #ifdef HAVE_PSI_STATEMENT_INTERFACE
1134 PSI_statement_info stmt_info_rpl;
1135 #endif
1136
1137 /* the default log output is log tables */
1138 static bool lower_case_table_names_used = false;
1139 #if !defined(_WIN32)
1140 static bool socket_listener_active = false;
1141 static int pipe_write_fd = -1;
1142 static bool opt_daemonize = false;
1143 #endif
1144 bool opt_debugging = false;
1145 static bool opt_external_locking = false, opt_console = false;
1146 static bool opt_short_log_format = false;
1147 static char *mysqld_user, *mysqld_chroot;
1148 static const char *default_character_set_name;
1149 static const char *character_set_filesystem_name;
1150 static const char *lc_messages;
1151 static const char *lc_time_names_name;
1152 char *my_bind_addr_str;
1153 char *my_admin_bind_addr_str;
1154 uint mysqld_admin_port;
1155 bool listen_admin_interface_in_separate_thread;
1156 char *my_proxy_protocol_networks;
1157 static const char *default_collation_name;
1158 const char *default_storage_engine;
1159 const char *default_tmp_storage_engine;
1160 ulonglong temptable_max_ram;
1161 ulonglong temptable_max_mmap;
1162 bool temptable_use_mmap;
1163 static char compiled_default_collation_name[] = MYSQL_DEFAULT_COLLATION_NAME;
1164 static bool binlog_format_used = false;
1165
1166 LEX_STRING opt_init_connect, opt_init_replica;
1167
1168 /* Global variables */
1169
1170 LEX_STRING opt_mandatory_roles;
1171 bool opt_mandatory_roles_cache = false;
1172 bool opt_always_activate_granted_roles = false;
1173 bool opt_bin_log;
1174 bool opt_general_log, opt_slow_log, opt_general_log_raw;
1175 ulonglong slow_query_log_always_write_time = 10000000;
1176 ulonglong log_output_options;
1177 bool opt_log_queries_not_using_indexes = false;
1178 ulong opt_log_throttle_queries_not_using_indexes = 0;
1179 bool opt_log_slow_extra = false;
1180 bool opt_disable_networking = false, opt_skip_show_db = false;
1181 bool opt_skip_name_resolve = false;
1182 bool opt_character_set_client_handshake = true;
1183 bool server_id_supplied = false;
1184 static bool opt_endinfo;
1185 bool using_udf_functions;
1186 bool locked_in_memory;
1187 bool opt_using_transactions;
1188 ulong opt_tc_log_size;
1189 std::atomic<int32> connection_events_loop_aborted_flag;
1190 static std::atomic<enum_server_operational_state> server_operational_state{
1191 SERVER_BOOTING};
1192 char *opt_log_error_suppression_list;
1193 char *opt_log_error_services;
1194 char *opt_keyring_migration_user = nullptr;
1195 char *opt_keyring_migration_host = nullptr;
1196 char *opt_keyring_migration_password = nullptr;
1197 char *opt_keyring_migration_socket = nullptr;
1198 char *opt_keyring_migration_source = nullptr;
1199 char *opt_keyring_migration_destination = nullptr;
1200 ulong opt_keyring_migration_port = 0;
1201 bool migrate_connect_options = false;
1202 uint host_cache_size;
1203 ulong log_error_verbosity = 3; // have a non-zero value during early start-up
1204 bool opt_keyring_migration_to_component = false;
1205 bool opt_libcoredumper, opt_corefile = 0;
1206 bool opt_persist_sensitive_variables_in_plaintext{true};
1207
1208 #if defined(_WIN32)
1209 /*
1210 Thread handle of shutdown event handler thread.
1211 It is used as argument during thread join.
1212 */
1213 my_thread_handle shutdown_restart_thr_handle;
1214
1215 ulong slow_start_timeout;
1216 bool opt_no_monitor = false;
1217 #endif
1218
1219 bool opt_no_dd_upgrade = false;
1220 long opt_upgrade_mode = UPGRADE_AUTO;
1221 bool opt_initialize = false;
1222 bool dd_init_failed_during_upgrade = false;
1223 bool opt_skip_replica_start = false; ///< If set, slave is not autostarted
1224 bool opt_enable_named_pipe = false;
1225 bool opt_local_infile, opt_replica_compressed_protocol;
1226 bool opt_safe_user_create = false;
1227 bool opt_show_replica_auth_info;
1228 bool opt_log_replica_updates = false;
1229 char *opt_replica_skip_errors;
1230 bool opt_replica_allow_batching = true;
1231
1232 /**
1233 compatibility option:
1234 - index usage hints (USE INDEX without a FOR clause) behave as in 5.0
1235 */
1236 bool old_mode;
1237
1238 /*
1239 Legacy global handlerton. These will be removed (please do not add more).
1240 */
1241 handlerton *heap_hton;
1242 handlerton *temptable_hton;
1243 handlerton *myisam_hton;
1244 handlerton *innodb_hton;
1245
1246 char *opt_disabled_storage_engines;
1247 uint opt_server_id_bits = 0;
1248 ulong opt_server_id_mask = 0;
1249 bool read_only = false, opt_readonly = false;
1250 bool super_read_only = false, opt_super_readonly = false;
1251 bool opt_require_secure_transport = false;
1252 bool relay_log_purge;
1253 bool relay_log_recovery;
1254 bool opt_allow_suspicious_udfs;
1255 const char *opt_secure_file_priv;
1256 const char *opt_secure_log_path;
1257 bool opt_log_slow_admin_statements = false;
1258 bool opt_log_slow_replica_statements = false;
1259 bool lower_case_file_system = false;
1260 bool opt_large_pages = false;
1261 bool opt_super_large_pages = false;
1262 bool opt_myisam_use_mmap = false;
1263 std::atomic<bool> offline_mode;
1264 uint opt_large_page_size = 0;
1265 uint default_password_lifetime = 0;
1266 ulonglong opt_slow_query_log_use_global_control = 0;
1267 ulong opt_slow_query_log_rate_type = 0;
1268 bool password_require_current = false;
1269 std::atomic<bool> partial_revokes;
1270 bool opt_partial_revokes; // Initialized through Sys_var
1271
1272 mysql_mutex_t LOCK_default_password_lifetime;
1273 mysql_mutex_t LOCK_mandatory_roles;
1274 mysql_mutex_t LOCK_password_history;
1275 mysql_mutex_t LOCK_password_reuse_interval;
1276 mysql_mutex_t LOCK_tls_ctx_options;
1277 mysql_mutex_t LOCK_admin_tls_ctx_options;
1278 mysql_mutex_t LOCK_partial_revokes;
1279
1280 #if defined(ENABLED_DEBUG_SYNC)
1281 MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout = 0;
1282 #endif /* defined(ENABLED_DEBUG_SYNC) */
1283 bool opt_old_style_user_limits = false, trust_function_creators = false;
1284 bool check_proxy_users = false, mysql_native_password_proxy_users = false,
1285 sha256_password_proxy_users = false;
1286 bool opt_userstat = false;
1287 bool opt_thread_statistics = false;
1288 /*
1289 True if there is at least one per-hour limit for some user, so we should
1290 check them before each query (and possibly reset counters when hour is
1291 changed). False otherwise.
1292 */
1293 volatile bool mqh_used = false;
1294 bool opt_noacl = false;
1295 bool sp_automatic_privileges = true;
1296
1297 int32_t opt_regexp_time_limit;
1298 int32_t opt_regexp_stack_limit;
1299
1300 /** True, if restarted from a cloned database. This information
1301 is needed by GR to set some configurations right after clone. */
1302 bool clone_startup = false;
1303
1304 /** True, if clone recovery has failed. For managed server we
1305 restart server again with old database files. */
1306 bool clone_recovery_error = false;
1307
1308 ulong binlog_row_event_max_size;
1309 ulong binlog_checksum_options;
1310 ulong binlog_row_metadata;
1311 bool opt_source_verify_checksum = false;
1312 bool opt_replica_sql_verify_checksum = true;
1313 const char *binlog_format_names[] = {"MIXED", "STATEMENT", "ROW", NullS};
1314 bool binlog_gtid_simple_recovery;
1315 ulong binlog_error_action;
1316 const char *binlog_error_action_list[] = {"IGNORE_ERROR", "ABORT_SERVER",
1317 NullS};
1318 bool opt_binlog_skip_flush_commands = false;
1319 uint32 gtid_executed_compression_period = 0;
1320 bool opt_log_unsafe_statements;
1321
1322 const char *timestamp_type_names[] = {"UTC", "SYSTEM", NullS};
1323 ulong opt_log_timestamps;
1324 uint mysqld_port, test_flags = 0, select_errors, ha_open_options;
1325 uint mysqld_port_timeout;
1326 ulong delay_key_write_options;
1327 uint protocol_version;
1328 uint lower_case_table_names;
1329 long tc_heuristic_recover;
1330 ulong back_log, connect_timeout, server_id;
1331 ulong table_cache_size;
1332 ulong table_cache_instances;
1333 ulong table_cache_size_per_instance;
1334 ulong schema_def_size;
1335 ulong stored_program_def_size;
1336 ulong table_def_size;
1337 ulong tablespace_def_size;
1338 ulong what_to_log;
1339 ulong slow_launch_time;
1340 std::atomic<int32> atomic_replica_open_temp_tables{0};
1341 ulong open_files_limit, max_binlog_size, max_relay_log_size;
1342 ulong slave_trans_retries;
1343 uint replica_net_timeout;
1344 ulong replica_exec_mode_options;
1345 ulonglong replica_type_conversions_options;
1346 ulong opt_mts_replica_parallel_workers;
1347 ulonglong opt_mts_pending_jobs_size_max;
1348 ulonglong slave_rows_search_algorithms_options;
1349 bool opt_replica_preserve_commit_order;
1350 #ifndef NDEBUG
1351 uint replica_rows_last_search_algorithm_used;
1352 #endif
1353 ulong mts_parallel_option;
1354 ulong binlog_cache_size = 0;
1355 ulonglong max_binlog_cache_size = 0;
1356 ulong net_buffer_shrink_interval = 0;
1357 ulong replica_max_allowed_packet = 0;
1358 ulong binlog_stmt_cache_size = 0;
1359 int32 opt_binlog_max_flush_queue_time = 0;
1360 long opt_binlog_group_commit_sync_delay = 0;
1361 ulong opt_binlog_group_commit_sync_no_delay_count = 0;
1362 ulonglong max_binlog_stmt_cache_size = 0;
1363 ulong refresh_version; /* Increments on each reload */
1364 std::atomic<query_id_t> atomic_global_query_id{1};
1365 ulong aborted_threads;
1366 ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
1367 ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
1368 ulong delayed_insert_errors, flush_time;
1369 ulong specialflag = 0;
1370 ulong binlog_cache_use = 0, binlog_cache_disk_use = 0;
1371 ulong binlog_stmt_cache_use = 0, binlog_stmt_cache_disk_use = 0;
1372 ulong max_connections, max_connect_errors;
1373 ulong rpl_stop_replica_timeout = LONG_TIMEOUT;
1374 bool log_bin_use_v1_row_events = false;
1375 bool thread_cache_size_specified = false;
1376 bool host_cache_size_specified = false;
1377 bool table_definition_cache_specified = false;
1378 ulong locked_account_connection_count = 0;
1379
1380 ulonglong denied_connections = 0;
1381 ulonglong global_conn_mem_limit = 0;
1382 ulonglong global_conn_mem_counter = 0;
1383
1384 /**
1385 This variable holds handle to the object that's responsible
1386 for loading/unloading components from manifest file
1387 */
1388 Deployed_components *g_deployed_components = nullptr;
1389
1390 /**
1391 Limit of the total number of prepared statements in the server.
1392 Is necessary to protect the server against out-of-memory attacks.
1393 */
1394 ulong max_prepared_stmt_count;
1395 /**
1396 Current total number of prepared statements in the server. This number
1397 is exact, and therefore may not be equal to the difference between
1398 `com_stmt_prepare' and `com_stmt_close' (global status variables), as
1399 the latter ones account for all registered attempts to prepare
1400 a statement (including unsuccessful ones). Prepared statements are
1401 currently connection-local: if the same SQL query text is prepared in
1402 two different connections, this counts as two distinct prepared
1403 statements.
1404 */
1405 ulong prepared_stmt_count = 0;
1406 ulong current_pid;
1407 uint sync_binlog_period = 0, sync_relaylog_period = 0,
1408 sync_relayloginfo_period = 0, sync_masterinfo_period = 0,
1409 opt_mta_checkpoint_period, opt_mta_checkpoint_group;
1410 ulong expire_logs_days = 0;
1411 ulong binlog_expire_logs_seconds = 0;
1412 bool opt_binlog_expire_logs_auto_purge{true};
1413 /**
1414 Soft upper limit for number of sp_head objects that can be stored
1415 in the sp_cache for one connection.
1416 */
1417 ulong stored_program_cache_size = 0;
1418 /**
1419 Compatibility option to prevent auto upgrade of old temporals
1420 during certain ALTER TABLE operations.
1421 */
1422 bool avoid_temporal_upgrade;
1423
1424 bool persisted_globals_load = true;
1425
1426 bool opt_keyring_operations = true;
1427
1428 bool opt_table_encryption_privilege_check = false;
1429
1430 const double log_10[] = {
1431 1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009, 1e010,
1432 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019, 1e020, 1e021,
1433 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029, 1e030, 1e031, 1e032,
1434 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039, 1e040, 1e041, 1e042, 1e043,
1435 1e044, 1e045, 1e046, 1e047, 1e048, 1e049, 1e050, 1e051, 1e052, 1e053, 1e054,
1436 1e055, 1e056, 1e057, 1e058, 1e059, 1e060, 1e061, 1e062, 1e063, 1e064, 1e065,
1437 1e066, 1e067, 1e068, 1e069, 1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076,
1438 1e077, 1e078, 1e079, 1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087,
1439 1e088, 1e089, 1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098,
1440 1e099, 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
1441 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119, 1e120,
1442 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129, 1e130, 1e131,
1443 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139, 1e140, 1e141, 1e142,
1444 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150, 1e151, 1e152, 1e153,
1445 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160, 1e161, 1e162, 1e163, 1e164,
1446 1e165, 1e166, 1e167, 1e168, 1e169, 1e170, 1e171, 1e172, 1e173, 1e174, 1e175,
1447 1e176, 1e177, 1e178, 1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186,
1448 1e187, 1e188, 1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197,
1449 1e198, 1e199, 1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208,
1450 1e209, 1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
1451 1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229, 1e230,
1452 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239, 1e240, 1e241,
1453 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249, 1e250, 1e251, 1e252,
1454 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259, 1e260, 1e261, 1e262, 1e263,
1455 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, 1e270, 1e271, 1e272, 1e273, 1e274,
1456 1e275, 1e276, 1e277, 1e278, 1e279, 1e280, 1e281, 1e282, 1e283, 1e284, 1e285,
1457 1e286, 1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296,
1458 1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307,
1459 1e308};
1460
1461 /* Index extension. */
1462 const int index_ext_length = 6;
1463 const char *index_ext = ".index";
1464 const int relay_ext_length = 10;
1465 const char *relay_ext = "-relay-bin";
1466 /* True if --log-bin option is used. */
1467 bool log_bin_supplied = false;
1468
1469 time_t server_start_time, flush_status_time;
1470
1471 char server_uuid[UUID_LENGTH + 1];
1472 const char *server_uuid_ptr;
1473 char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN];
1474 char system_time_zone_dst_on[30], system_time_zone_dst_off[30];
1475 char default_logfile_name[FN_REFLEN];
1476 char default_binlogfile_name[FN_REFLEN];
1477 char default_binlog_index_name[FN_REFLEN + index_ext_length];
1478 char default_relaylogfile_name[FN_REFLEN + relay_ext_length];
1479 char default_relaylog_index_name[FN_REFLEN + relay_ext_length +
1480 index_ext_length];
1481 char *default_tz_name;
1482 static char errorlog_filename_buff[FN_REFLEN];
1483 const char *log_error_dest;
1484 const char *my_share_dir[FN_REFLEN];
1485 char glob_hostname[HOSTNAME_LENGTH + 1];
1486 char mysql_real_data_home[FN_REFLEN], lc_messages_dir[FN_REFLEN],
1487 reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN], *opt_init_file;
1488 const char *opt_tc_log_file;
1489 char *lc_messages_dir_ptr;
1490 char mysql_unpacked_real_data_home[FN_REFLEN];
1491 size_t mysql_unpacked_real_data_home_len;
1492 size_t mysql_data_home_len = 1;
1493 uint reg_ext_length;
1494 char logname_path[FN_REFLEN];
1495 char slow_logname_path[FN_REFLEN];
1496 char secure_file_real_path[FN_REFLEN];
1497 char secure_log_real_path[FN_REFLEN];
1498 Time_zone *default_tz;
1499 char *mysql_data_home = const_cast<char *>(".");
1500 const char *mysql_real_data_home_ptr = mysql_real_data_home;
1501 char *opt_protocol_compression_algorithms;
1502 char server_version[SERVER_VERSION_LENGTH];
1503 char server_version_suffix[SERVER_VERSION_LENGTH];
1504 const char *mysqld_unix_port;
1505 char *opt_mysql_tmpdir;
1506
1507 char *opt_authentication_policy;
1508 std::vector<std::string> authentication_policy_list;
1509 /*
1510 keep track of plugin_ref until plugins used in opt_authentication_policy
1511 are properly validated and updated. This will ensure that plugin is not
1512 unloaded in between check() and update() of authentication_policy variable
1513 */
1514 std::vector<plugin_ref> authentication_policy_plugin_ref;
1515
1516 bool encrypt_tmp_files;
1517
1518 ulonglong tf_sequence_table_max_upper_bound = 0;
1519
1520 /** name of reference on left expression in rewritten IN subquery */
1521 const char *in_left_expr_name = "<left expr>";
1522
1523 my_decimal decimal_zero;
1524 /** Number of connection errors from internal server errors. */
1525 ulong connection_errors_internal = 0;
1526 /** Number of errors when reading the peer address. */
1527 ulong connection_errors_peer_addr = 0;
1528
1529 /* classes for comparison parsing/processing */
1530 Eq_creator eq_creator;
1531 Ne_creator ne_creator;
1532 Equal_creator equal_creator;
1533 Gt_creator gt_creator;
1534 Lt_creator lt_creator;
1535 Ge_creator ge_creator;
1536 Le_creator le_creator;
1537
1538 Rpl_global_filter rpl_global_filter;
1539 Rpl_filter *binlog_filter;
1540 Rpl_acf_configuration_handler *rpl_acf_configuration_handler = nullptr;
1541 Source_IO_monitor *rpl_source_io_monitor = nullptr;
1542 Udf_load_service udf_load_service;
1543
1544 struct System_variables global_system_variables;
1545 struct System_variables max_system_variables;
1546 struct System_status_var global_status_var;
1547
1548 MY_TMPDIR mysql_tmpdir_list;
1549
1550 CHARSET_INFO *system_charset_info, *files_charset_info;
1551 CHARSET_INFO *national_charset_info, *table_alias_charset;
1552 CHARSET_INFO *character_set_filesystem;
1553
1554 MY_LOCALE *my_default_lc_messages;
1555 MY_LOCALE *my_default_lc_time_names;
1556
1557 SHOW_COMP_OPTION have_symlink, have_dlopen, have_query_cache;
1558 SHOW_COMP_OPTION have_geometry, have_rtree_keys;
1559 SHOW_COMP_OPTION have_compress;
1560 SHOW_COMP_OPTION have_profiling;
1561 SHOW_COMP_OPTION have_statement_timeout = SHOW_OPTION_DISABLED;
1562 SHOW_COMP_OPTION have_backup_locks;
1563 SHOW_COMP_OPTION have_backup_safe_binlog_info;
1564 SHOW_COMP_OPTION have_snapshot_cloning;
1565
1566 char *enforce_storage_engine = nullptr;
1567
1568 char *utility_user = nullptr;
1569 char *utility_user_password = nullptr;
1570 char *utility_user_schema_access = nullptr;
1571
1572 char *opt_libcoredumper_path = NULL;
1573 /* Plucking this from sql/sql_acl.cc for an array of privilege names */
1574 extern TYPELIB utility_user_privileges_typelib;
1575 ulonglong utility_user_privileges = 0;
1576 char *utility_user_dynamic_privileges = nullptr;
1577
1578 /* Thread specific variables */
1579
1580 thread_local MEM_ROOT **THR_MALLOC = nullptr;
1581
1582 mysql_mutex_t LOCK_status, LOCK_uuid_generator, LOCK_crypt,
1583 LOCK_global_system_variables, LOCK_user_conn, LOCK_error_messages;
1584 mysql_mutex_t LOCK_sql_rand;
1585
1586 mysql_mutex_t LOCK_global_user_client_stats, LOCK_global_table_stats,
1587 LOCK_global_index_stats;
1588 /**
1589 The below lock protects access to two global server variables:
1590 max_prepared_stmt_count and prepared_stmt_count. These variables
1591 set the limit and hold the current total number of prepared statements
1592 in the server, respectively. As PREPARE/DEALLOCATE rate in a loaded
1593 server may be fairly high, we need a dedicated lock.
1594 */
1595 mysql_mutex_t LOCK_prepared_stmt_count;
1596
1597 /**
1598 Protects slave_list in rpl_source.cc; the list of currently running
1599 dump threads with metadata for the replica.
1600 */
1601 mysql_mutex_t LOCK_replica_list;
1602 /*
1603 The below two locks are introduced as guards (second mutex) for
1604 the global variables sql_replica_skip_counter and replica_net_timeout
1605 respectively. See fix_slave_skip_counter/fix_replica_net_timeout
1606 for more details
1607 */
1608 mysql_mutex_t LOCK_sql_replica_skip_counter;
1609 mysql_mutex_t LOCK_replica_net_timeout;
1610 mysql_mutex_t LOCK_replica_trans_dep_tracker;
1611 mysql_mutex_t LOCK_log_throttle_qni;
1612 mysql_rwlock_t LOCK_sys_init_connect, LOCK_sys_init_replica;
1613 mysql_rwlock_t LOCK_system_variables_hash;
1614 my_thread_handle signal_thread_id;
1615 sigset_t mysqld_signal_mask;
1616 my_thread_attr_t connection_attrib;
1617 mysql_mutex_t LOCK_server_started;
1618 mysql_cond_t COND_server_started;
1619 mysql_mutex_t LOCK_reset_gtid_table;
1620 mysql_mutex_t LOCK_compress_gtid_table;
1621 mysql_cond_t COND_compress_gtid_table;
1622 mysql_mutex_t LOCK_collect_instance_log;
1623 #if !defined(_WIN32)
1624 mysql_mutex_t LOCK_socket_listener_active;
1625 mysql_cond_t COND_socket_listener_active;
1626 mysql_mutex_t LOCK_start_signal_handler;
1627 mysql_cond_t COND_start_signal_handler;
1628 #endif
1629 mysql_rwlock_t LOCK_consistent_snapshot;
1630
1631 /*
1632 The below lock protects access to global server variable
1633 keyring_operations.
1634 */
1635 mysql_mutex_t LOCK_keyring_operations;
1636 /*
1637 The below lock protects to execute commands 'ALTER INSTANCE ROTATE BINLOG
1638 MASTER KEY' and 'SET @@GLOBAL.binlog_encryption=ON/OFF' in parallel.
1639 */
1640 mysql_mutex_t LOCK_rotate_binlog_master_key;
1641
1642 /*
1643 The below lock protects to execute commands 'CREATE/ALTER USER' and
1644 'SET @@GLOBAL.authentication_policy...' in parallel.
1645 */
1646 mysql_mutex_t LOCK_authentication_policy;
1647
1648 mysql_mutex_t LOCK_global_conn_mem_limit;
1649
1650 bool mysqld_server_started = false;
1651 /**
1652 Set to true to signal at startup if the process must die.
1653
1654 Needed because kill_mysql() will not do anything before
1655 the server is fully initialized. Thus it now just sets this
1656 flag to on and exits. And then mysqld_main() will check if
1657 the flag is on at the right place and exit the process if it
1658 is.
1659 */
1660 static bool mysqld_process_must_end_at_startup = false;
1661
1662 /* replication parameters, if master_host is not NULL, we are a slave */
1663 uint report_port = 0;
1664 ulong master_retry_count = 0;
1665 const char *master_info_file;
1666 const char *relay_log_info_file;
1667 char *report_user, *report_password, *report_host;
1668 char *opt_relay_logname = nullptr, *opt_relaylog_index_name = nullptr;
1669 /*
1670 True if the --relay-log-index is set by users from
1671 config file or command line.
1672 */
1673 bool opt_relaylog_index_name_supplied = false;
1674 /*
1675 True if the --relay-log is set by users from
1676 config file or command line.
1677 */
1678 bool opt_relay_logname_supplied = false;
1679 /*
1680 True if --log-replica-updates option is set explicitly
1681 on command line or configuration file.
1682 */
1683 bool log_replica_updates_supplied = false;
1684
1685 /*
1686 True if --replica-preserve-commit-order-supplied option is set explicitly
1687 on command line or configuration file.
1688 */
1689 bool replica_preserve_commit_order_supplied = false;
1690 char *opt_general_logname, *opt_slow_logname, *opt_bin_logname;
1691
1692 /*
1693 True if expire_logs_days and binlog_expire_logs_seconds are set
1694 explicitly.
1695 */
1696 bool expire_logs_days_supplied = false;
1697 bool binlog_expire_logs_seconds_supplied = false;
1698 /* Static variables */
1699
1700 static bool opt_myisam_log;
1701 static int cleanup_done;
1702 static ulong opt_specialflag;
1703 char *opt_binlog_index_name;
1704 char *mysql_home_ptr, *pidfile_name_ptr;
1705 char *default_auth_plugin;
1706 /**
1707 Memory for allocating command line arguments, after load_defaults().
1708 */
1709 static MEM_ROOT argv_alloc{PSI_NOT_INSTRUMENTED, 512};
1710 /** Remaining command line arguments (count), filtered by handle_options().*/
1711 static int remaining_argc;
1712 /** Remaining command line arguments (arguments), filtered by
1713 * handle_options().*/
1714 static char **remaining_argv;
1715
1716 /**
1717 Holds the "original" (i.e. as on startup) set of arguments.
1718
1719 The argument processing goes as follows:
1720 1. At startup the "original" set of arguments is shallow-copied into
1721 the read only list @ref orig_argv.
1722 2. The config file arguments are read from the config files (.cnf and
1723 persisted read-only) and are appended as command line arguments.
1724 In the process the argv is deep copied because of the expansion
1725 3. The result from 2 is set into @ref remaining_argv / @ref remaining_argc.
1726 4. Then remaining_argv is fed into various consumers:
1727 - the server compiled in set of arguments
1728 - the early plugins
1729 - the rest of the plugins
1730 - the error log
1731 - the components from the persisted dynamic loader init.
1732 All of the above "take away" the values they match from the extended
1733 command line set. And vary the values of @ref my_getopt_skip_unknown
1734 according to their needs (mostly keep it set).
1735 As a result, when the server is done booting up the things that remain
1736 in remaining_argv become less and less.
1737 5. When the bootstrap process is done a check is run:
1738 my_getopt_skip_unknown is set to off and the argument parser is called
1739 on remaining_argv with an empty set of argument definitions.
1740 This ensures that all of the remaining argument values in remaining_argv
1741 are either marked as "loose" (i.e. optional) or are "consumed" by prior
1742 argument list processings.
1743 The side effect of this is that all --loose arguments are also consumed
1744 out of remaining_argv.
1745 6. A check is made if the remaining_argv is an empty list. If not the server
1746 exits.
1747 7. At this point the server is marked as successfully started.
1748 8. Subsequent argument processings happen when e.g. a plugin is loaded via
1749 @ref mysql_install_plugin or a component registers system variables via
1750 @ref mysql_component_sys_variable_imp::register_variable. However, since
1751 remaining_argv is empty these need to run over the orig_argc/orig_argv.
1752 But argument value assignment would normally "eat" out the values found.
1753 This would mean that the orig_argv array will get shortened and if you
1754 load the same plugin twice for example its system variables will not have
1755 the values supplied the second time they start.
1756 Thus once the server is started (@ref mysqld_server_started is on) any
1757 argument value parsing should happen over a *copy* of orig_argc/orig_argv
1758 that should subsequently be discarded.
1759 @ref remaining_argv should not be consulted anymore at this point.
1760 */
1761 int orig_argc;
1762 char **orig_argv;
1763 namespace {
1764 FILE *nstdout = nullptr;
1765 char my_progpath[FN_REFLEN];
1766 const char *my_orig_progname = nullptr;
1767
1768 /**
1769 This variable holds the exit value of the signal handler thread.
1770 */
1771 std::atomic<int> signal_hand_thr_exit_code(MYSQLD_SUCCESS_EXIT);
1772
1773 /**
1774 Inspects the program name in argv[0] and substitutes the full path
1775 of the executable.
1776
1777 @param argv argument vector (array) for executable.
1778 */
1779 12121 void substitute_progpath(char **argv) {
1780
2/2
✓ Branch 0 taken 12119 times.
✓ Branch 1 taken 2 times.
12121 if (test_if_hard_path(argv[0])) return;
1781
1782 #if defined(_WIN32)
1783 if (GetModuleFileName(NULL, my_progpath, sizeof(my_progpath))) {
1784 my_orig_progname = argv[0];
1785 argv[0] = my_progpath;
1786 }
1787 #else
1788 /* If the path has a directory component, use my_realpath()
1789 (implicitly relative to cwd) */
1790
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
3 if (strchr(argv[0], FN_LIBCHAR) != nullptr &&
1791
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 !my_realpath(my_progpath, argv[0], MYF(0))) {
1792 1 my_orig_progname = argv[0];
1793 1 argv[0] = my_progpath;
1794 1 return;
1795 }
1796
1797 // my_realpath() cannot resolve it, it must be a bare executable
1798 // name in path
1799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(strchr(argv[0], FN_LIBCHAR) == nullptr);
1800
1801 1 const char *spbegin = getenv("PATH");
1802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (spbegin == nullptr) spbegin = "";
1803 1 const char *spend = spbegin + strlen(spbegin);
1804
1805 while (true) {
1806
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 const char *colonend = std::find(spbegin, spend, ':');
1807
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string cand{spbegin, colonend};
1808 1 spbegin = colonend + 1;
1809
1810
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cand.append(1, '/');
1811
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cand.append(argv[0]);
1812
1813
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (my_access(cand.c_str(), X_OK) == 0) {
1814
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (my_realpath(my_progpath, cand.c_str(), MYF(0))) {
1815 // Fallback to raw cand
1816 assert(cand.length() < FN_REFLEN);
1817 std::copy(cand.begin(), cand.end(), my_progpath);
1818 my_progpath[cand.length()] = '\0';
1819 }
1820 1 my_orig_progname = argv[0];
1821 1 argv[0] = my_progpath;
1822 1 break;
1823 }
1824 if (colonend == spend) {
1825 assert(false);
1826 break;
1827 }
1828
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 } // while (true)
1829 #endif // defined(_WIN32)
1830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (my_orig_progname == nullptr) {
1831 LogErr(WARNING_LEVEL, ER_FAILED_TO_GET_ABSOLUTE_PATH, argv[0]);
1832 }
1833 }
1834 } // namespace
1835
1836 static Connection_acceptor<Mysqld_socket_listener> *mysqld_socket_acceptor =
1837 nullptr;
1838 #ifdef _WIN32
1839 static Named_pipe_listener *named_pipe_listener = NULL;
1840 Connection_acceptor<Named_pipe_listener> *named_pipe_acceptor = NULL;
1841 Connection_acceptor<Shared_mem_listener> *shared_mem_acceptor = NULL;
1842 mysql_rwlock_t LOCK_named_pipe_full_access_group;
1843 char *named_pipe_full_access_group;
1844 #endif
1845
1846 Checkable_rwlock *global_sid_lock = nullptr;
1847 Sid_map *global_sid_map = nullptr;
1848 Gtid_state *gtid_state = nullptr;
1849 Gtid_table_persistor *gtid_table_persistor = nullptr;
1850
1851 /* cache for persisted variables */
1852 static Persisted_variables_cache persisted_variables_cache;
1853
1854 12 void persisted_variables_refresh_keyring_support() {
1855 12 persisted_variables_cache.keyring_support_available();
1856 12 }
1857
1858 33 void set_remaining_args(int argc, char **argv) {
1859 33 remaining_argc = argc;
1860 33 remaining_argv = argv;
1861 33 }
1862
1863 127 int *get_remaining_argc() { return &remaining_argc; }
1864
1865 127 char ***get_remaining_argv() { return &remaining_argv; }
1866
1867 /*
1868 Multiple threads of execution use the random state maintained in global
1869 sql_rand to generate random numbers. sql_rnd_with_mutex use mutex
1870 LOCK_sql_rand to protect sql_rand across multiple instantiations that use
1871 sql_rand to generate random numbers.
1872 */
1873 1358842 ulong sql_rnd_with_mutex() {
1874 1358842 mysql_mutex_lock(&LOCK_sql_rand);
1875 ulong tmp =
1876 1359202 (ulong)(my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
1877 1359202 mysql_mutex_unlock(&LOCK_sql_rand);
1878 1359202 return tmp;
1879 }
1880
1881 360793 struct System_status_var *get_thd_status_var(THD *thd, bool *aggregated) {
1882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 360793 times.
360793 assert(thd != nullptr);
1883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 360793 times.
360793 assert(aggregated != nullptr);
1884 360793 *aggregated = thd->status_var_aggregated;
1885 360793 return &thd->status_var;
1886 }
1887
1888 #ifndef NDEBUG
1889 18932808 bool thd_mem_cnt_alloc(THD *thd, size_t size, const char *key_name) {
1890 18932808 thd->current_key_name = key_name;
1891 18932808 return thd->m_mem_cnt.alloc_cnt(size);
1892 }
1893 #else
1894 bool thd_mem_cnt_alloc(THD *thd, size_t size) {
1895 return thd->m_mem_cnt.alloc_cnt(size);
1896 }
1897 #endif
1898
1899 18079630 void thd_mem_cnt_free(THD *thd, size_t size) { thd->m_mem_cnt.free_cnt(size); }
1900
1901 12110 static void option_error_reporter(enum loglevel level, uint ecode, ...) {
1902 va_list args;
1903 12110 va_start(args, ecode);
1904
1905 /*
1906 Don't print warnings for --loose options during initialize.
1907 */
1908
5/6
✓ Branch 0 taken 12075 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 11936 times.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
12110 if (level == ERROR_LEVEL || !opt_initialize || (log_error_verbosity > 1)) {
1909
1/2
✓ Branch 0 taken 12110 times.
✗ Branch 1 not taken.
12110 error_log_print(level, ecode, args);
1910 }
1911 12110 va_end(args);
1912 12110 }
1913
1914 /**
1915 Character set and collation error reporter that prints to sql error log.
1916 @param level log message level
1917 @param ecode Error code of the error message.
1918
1919 This routine is used to print character set and collation
1920 warnings and errors inside an already running mysqld server,
1921 e.g. when a character set or collation is requested for the very first time
1922 and its initialization does not go well for some reasons.
1923 */
1924
1925 5 static void charset_error_reporter(enum loglevel level, uint ecode, ...) {
1926 va_list args;
1927 5 va_start(args, ecode);
1928
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 error_log_print(level, ecode, args);
1929 5 va_end(args);
1930 5 }
1931
1932 struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
1933
1934 #ifndef _WIN32
1935 PasswdValue user_info;
1936 static my_thread_t main_thread_id;
1937 #endif // !_WIN32
1938
1939 /* OS specific variables */
1940
1941 #ifdef _WIN32
1942 static bool mysqld_early_option = false;
1943 static bool windows_service = false;
1944 static bool use_opt_args;
1945 static int opt_argc;
1946 static char **opt_argv;
1947 static char **my_global_argv = nullptr;
1948 static int my_global_argc;
1949
1950 static mysql_mutex_t LOCK_handler_count;
1951 static mysql_cond_t COND_handler_count;
1952 static HANDLE hEventShutdown;
1953 static HANDLE hEventRestart;
1954 const char *shared_memory_base_name = default_shared_memory_base_name;
1955 bool opt_enable_shared_memory;
1956 static char shutdown_event_name[40];
1957 static char restart_event_name[40];
1958 static NTService Service; ///< Service object for WinNT
1959 #endif /* _WIN32 */
1960
1961 /**
1962 Flag indicating if dynamic plugins have been loaded. Only to be accessed
1963 by main thread.
1964 */
1965 bool dynamic_plugins_are_initialized = false;
1966
1967 #ifndef NDEBUG
1968 static const char *default_dbug_option;
1969 #endif
1970
1971 bool opt_use_ssl = true;
1972 bool opt_use_admin_ssl = true;
1973 ulong opt_ssl_fips_mode = SSL_FIPS_MODE_OFF;
1974
1975 /* Function declarations */
1976
1977 static int mysql_init_variables();
1978 static int get_options(int *argc_ptr, char ***argv_ptr);
1979 static void add_terminator(vector<my_option> *options);
1980 extern "C" bool mysqld_get_one_option(int, const struct my_option *, char *);
1981 static void set_server_version(void);
1982 static int init_thread_environment();
1983 static const char *get_relative_path(const char *path);
1984 static int fix_paths(void);
1985 static int test_if_case_insensitive(const char *dir_name);
1986 static void end_ssl();
1987 static void delete_dictionary_tablespace();
1988
1989 extern "C" void *signal_hand(void *arg);
1990 static bool pid_file_created = false;
1991 static void usage(void);
1992 static void clean_up_mutexes(void);
1993 static bool create_pid_file();
1994 [[noreturn]] static void mysqld_exit(int exit_code);
1995 static void delete_pid_file(myf flags);
1996 static void clean_up(bool print_message);
1997 static int handle_early_options();
1998 static void adjust_related_options(ulong *requested_open_files);
1999 static void process_bootstrap();
2000 #ifdef HAVE_PSI_INTERFACE
2001 static void init_server_psi_keys();
2002 #endif
2003
2004 /**
2005 Notify any waiters that the server components have been initialized.
2006 Used by the signal handler thread and by Cluster.
2007
2008 @see signal_hand
2009 */
2010
2011 11977 static void server_components_initialized() {
2012 11977 mysql_mutex_lock(&LOCK_server_started);
2013 11977 mysqld_server_started = true;
2014 11977 mysql_cond_broadcast(&COND_server_started);
2015 11977 mysql_mutex_unlock(&LOCK_server_started);
2016 11977 }
2017
2018 SERVICE_TYPE(mysql_runtime_error) * error_service;
2019 SERVICE_TYPE(mysql_psi_system_v1) * system_service;
2020 SERVICE_TYPE(mysql_rwlock_v1) * rwlock_service;
2021 SERVICE_TYPE_NO_CONST(registry) * srv_registry;
2022 SERVICE_TYPE(dynamic_loader_scheme_file) * scheme_file_srv;
2023 using loader_type_t = SERVICE_TYPE_NO_CONST(dynamic_loader);
2024 using runtime_error_type_t = SERVICE_TYPE_NO_CONST(mysql_runtime_error);
2025 using psi_system_type_t = SERVICE_TYPE_NO_CONST(mysql_psi_system_v1);
2026 using rwlock_type_t = SERVICE_TYPE_NO_CONST(mysql_rwlock_v1);
2027 using loader_scheme_type_t = SERVICE_TYPE_NO_CONST(dynamic_loader_scheme_file);
2028 extern REQUIRES_SERVICE_PLACEHOLDER(mysql_rwlock_v1);
2029 extern REQUIRES_SERVICE_PLACEHOLDER(mysql_psi_system_v1);
2030 extern bool initialize_minimal_chassis(SERVICE_TYPE_NO_CONST(registry) *
2031 *registry);
2032 extern bool deinitialize_minimal_chassis(SERVICE_TYPE_NO_CONST(registry) *
2033 registry);
2034 /*
2035 List of components to be loaded directly using dynamic loader load.
2036 These components should to be present in the plugin directory path.
2037 */
2038 const char *component_urns[] = {"file://component_reference_cache"};
2039 #define NUMBER_OF_COMPONENTS 1
2040
2041 /**
2042 Initializes component infrastructure by bootstrapping core component
2043 subsystem.
2044
2045 @return Status of performed operation
2046 @retval false success
2047 @retval true failure
2048 */
2049 12109 static bool component_infrastructure_init() {
2050 12109 bool retval = false;
2051
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 if (initialize_minimal_chassis(&srv_registry)) {
2052 LogErr(ERROR_LEVEL, ER_COMPONENTS_INFRASTRUCTURE_BOOTSTRAP);
2053 return true;
2054 }
2055 /* Here minimal_chassis dynamic_loader_scheme_file service has
2056 to be acquired */
2057
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 srv_registry->acquire(
2058 "dynamic_loader_scheme_file.mysql_minimal_chassis",
2059 reinterpret_cast<my_h_service *>(
2060 const_cast<loader_scheme_type_t **>(&scheme_file_srv)));
2061
2062
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 srv_registry->acquire("dynamic_loader",
2063 reinterpret_cast<my_h_service *>(
2064 const_cast<loader_type_t **>(&dynamic_loader_srv)));
2065
2066 my_service<SERVICE_TYPE(registry_registration)> registrator(
2067
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 "registry_registration", srv_registry);
2068
2069 // Sets default file scheme loader for MySQL server.
2070
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
12109 registrator->set_default(
2071 "dynamic_loader_scheme_file.mysql_server_path_filter");
2072
2073 // Sets default rw_lock for MySQL server.
2074
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
12109 registrator->set_default("mysql_rwlock_v1.mysql_server");
2075
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 srv_registry->acquire("mysql_rwlock_v1.mysql_server",
2076 reinterpret_cast<my_h_service *>(
2077 const_cast<rwlock_type_t **>(&rwlock_service)));
2078 12109 mysql_service_mysql_rwlock_v1 =
2079 reinterpret_cast<SERVICE_TYPE(mysql_rwlock_v1) *>(rwlock_service);
2080
2081 // Sets default psi_system event service for MySQL server.
2082
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
12109 registrator->set_default("mysql_psi_system_v1.mysql_server");
2083
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 srv_registry->acquire("mysql_psi_system_v1.mysql_server",
2084 reinterpret_cast<my_h_service *>(
2085 const_cast<psi_system_type_t **>(&system_service)));
2086 /* This service variable is needed for mysql_unload_plugin */
2087 12109 mysql_service_mysql_psi_system_v1 =
2088 reinterpret_cast<SERVICE_TYPE(mysql_psi_system_v1) *>(system_service);
2089
2090 // Sets default mysql_runtime_error for MySQL server.
2091
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
12109 registrator->set_default("mysql_runtime_error.mysql_server");
2092
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 srv_registry->acquire(
2093 "mysql_runtime_error.mysql_server",
2094 reinterpret_cast<my_h_service *>(
2095 const_cast<runtime_error_type_t **>(&error_service)));
2096 /* This service variable is needed where ever mysql_error_service_printf()
2097 service api is used */
2098 12109 mysql_service_mysql_runtime_error =
2099 reinterpret_cast<SERVICE_TYPE(mysql_runtime_error) *>(error_service);
2100
2101 12109 return retval;
2102 12109 }
2103
2104 /**
2105 This function is used to initialize the mysql_server component services.
2106 */
2107 11443 static void server_component_init() { mysql_comp_sys_var_services_init(); }
2108
2109 /**
2110 Initializes MySQL Server component infrastructure part by initialize of
2111 dynamic loader persistence.
2112
2113 @return Status of performed operation
2114 @retval false success
2115 @retval true failure
2116 */
2117
2118 11443 static bool mysql_component_infrastructure_init() {
2119 /* We need a temporary THD during boot */
2120
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 Auto_THD thd;
2121 11443 Disable_autocommit_guard autocommit_guard(thd.thd);
2122 dd::cache::Dictionary_client::Auto_releaser scope_releaser(
2123
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 thd.thd->dd_client());
2124
2/4
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11443 times.
11443 if (persistent_dynamic_loader_init(thd.thd)) {
2125 LogErr(ERROR_LEVEL, ER_COMPONENTS_PERSIST_LOADER_BOOTSTRAP);
2126 trans_rollback_stmt(thd.thd);
2127 // Full rollback in case we have THD::transaction_rollback_request.
2128 trans_rollback(thd.thd);
2129 return true;
2130 }
2131
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 server_component_init();
2132
4/8
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11443 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11443 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 11443 times.
11443 return trans_commit_stmt(thd.thd) || trans_commit(thd.thd);
2133 11443 }
2134
2135 /**
2136 De-initializes Component infrastructure by de-initialization of the MySQL
2137 Server services (persistent dynamic loader) followed by de-initailization of
2138 the core Components infrostructure.
2139
2140 @return Status of performed operation
2141 @retval false success
2142 @retval true failure
2143 */
2144 10491 static bool component_infrastructure_deinit() {
2145 10491 persistent_dynamic_loader_deinit();
2146 10491 bool retval = false;
2147
2148 10491 srv_registry->release(reinterpret_cast<my_h_service>(
2149 const_cast<loader_scheme_type_t *>(scheme_file_srv)));
2150 10491 srv_registry->release(reinterpret_cast<my_h_service>(
2151 const_cast<loader_type_t *>(dynamic_loader_srv)));
2152 10491 srv_registry->release(reinterpret_cast<my_h_service>(
2153 const_cast<runtime_error_type_t *>(error_service)));
2154 10491 srv_registry->release(reinterpret_cast<my_h_service>(
2155 const_cast<psi_system_type_t *>(system_service)));
2156 10491 srv_registry->release(reinterpret_cast<my_h_service>(
2157 const_cast<rwlock_type_t *>(rwlock_service)));
2158
2159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10491 times.
10491 if (deinitialize_minimal_chassis(srv_registry)) {
2160 LogErr(ERROR_LEVEL, ER_COMPONENTS_INFRASTRUCTURE_SHUTDOWN);
2161 retval = true;
2162 }
2163 10491 return retval;
2164 }
2165
2166 12109 static bool initialize_manifest_file_components() {
2167 /*
2168 Read components from manifest file
2169
2170 Note that the word 'components' is used differently in the server.
2171 Here we address the component service infrastructure, but in other places,
2172 like init_server_components() the word is used in bit different context
2173 and may mean general idea of modularity.
2174 */
2175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 assert(strlen(mysql_real_data_home) > 0);
2176
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
24218 g_deployed_components =
2177
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
12109 new (std::nothrow) Deployed_components(my_progname, mysql_real_data_home);
2178
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
24218 if (g_deployed_components == nullptr ||
2179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 g_deployed_components->valid() == false) {
2180 /*Error would have been raised by Deployed_components constructor */
2181 g_deployed_components = nullptr;
2182 return true;
2183 }
2184 12109 return false;
2185 }
2186
2187 10491 static void deinitialize_manifest_file_components() {
2188
1/2
✓ Branch 0 taken 10491 times.
✗ Branch 1 not taken.
10491 if (g_deployed_components != nullptr) {
2189 /* Error if any would have been raised */
2190
1/2
✓ Branch 0 taken 10491 times.
✗ Branch 1 not taken.
10491 delete g_deployed_components;
2191 10491 g_deployed_components = nullptr;
2192 }
2193 10491 }
2194
2195 /**
2196 Block and wait until server components have been initialized.
2197 */
2198
2199 11691 static void server_components_init_wait() {
2200 11691 mysql_mutex_lock(&LOCK_server_started);
2201
2/2
✓ Branch 0 taken 9749 times.
✓ Branch 1 taken 11691 times.
21440 while (!mysqld_server_started)
2202 9749 mysql_cond_wait(&COND_server_started, &LOCK_server_started);
2203 11691 mysql_mutex_unlock(&LOCK_server_started);
2204 11691 }
2205
2206 /****************************************************************************
2207 ** Code to end mysqld
2208 ****************************************************************************/
2209
2210 /**
2211 This class implements callback function used by close_connections()
2212 to set KILL_CONNECTION flag on all thds in thd list.
2213 If m_kill_dump_thread_flag is not set it kills all other threads
2214 except dump threads. If this flag is set, it kills dump threads.
2215 */
2216 class Set_kill_conn : public Do_THD_Impl {
2217 private:
2218 int m_dump_thread_count;
2219 bool m_kill_dump_threads_flag;
2220
2221 public:
2222 10103 Set_kill_conn() : m_dump_thread_count(0), m_kill_dump_threads_flag(false) {}
2223
2224 169 void set_dump_thread_flag() { m_kill_dump_threads_flag = true; }
2225
2226 10103 int get_dump_thread_count() const { return m_dump_thread_count; }
2227
2228 20857 void operator()(THD *killing_thd) override {
2229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20857 times.
20857 DBUG_PRINT("quit", ("Informing thread %u that it's time to die",
2230 killing_thd->thread_id()));
2231
2/2
✓ Branch 0 taken 19872 times.
✓ Branch 1 taken 985 times.
20857 if (!m_kill_dump_threads_flag) {
2232 // We skip slave threads & scheduler on this first loop through.
2233
2/2
✓ Branch 0 taken 1127 times.
✓ Branch 1 taken 18745 times.
19872 if (killing_thd->slave_thread) return;
2234
2235
6/6
✓ Branch 0 taken 18637 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 18571 times.
✓ Branch 4 taken 174 times.
✓ Branch 5 taken 18571 times.
37382 if (killing_thd->get_command() == COM_BINLOG_DUMP ||
2236 18637 killing_thd->get_command() == COM_BINLOG_DUMP_GTID) {
2237 174 ++m_dump_thread_count;
2238 174 return;
2239 }
2240
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18571 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18571 DBUG_EXECUTE_IF("Check_dump_thread_is_alive", {
2241 assert(killing_thd->get_command() != COM_BINLOG_DUMP &&
2242 killing_thd->get_command() != COM_BINLOG_DUMP_GTID);
2243 };);
2244 }
2245 19556 mysql_mutex_lock(&killing_thd->LOCK_thd_data);
2246
2247
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 19546 times.
19556 if (killing_thd->kill_immunizer) {
2248 /*
2249 If killing_thd is in kill immune mode (i.e. operation on new DD tables
2250 is in progress) then just save state_to_set with THD::kill_immunizer
2251 object.
2252
2253 While exiting kill immune mode, awake() is called again with the killed
2254 state saved in THD::kill_immunizer object.
2255 */
2256 10 killing_thd->kill_immunizer->save_killed_state(THD::KILL_CONNECTION);
2257 } else {
2258 19546 killing_thd->killed = THD::KILL_CONNECTION;
2259
2260
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 19522 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
19546 MYSQL_CALLBACK(killing_thd->scheduler, post_kill_notification,
2261 (killing_thd));
2262 }
2263
2264
3/4
✓ Branch 0 taken 19556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19546 times.
✓ Branch 3 taken 10 times.
19556 if (killing_thd->is_killable && killing_thd->kill_immunizer == nullptr) {
2265 19546 mysql_mutex_lock(&killing_thd->LOCK_current_cond);
2266
2/2
✓ Branch 0 taken 10166 times.
✓ Branch 1 taken 9380 times.
19546 if (killing_thd->current_cond.load()) {
2267 10166 mysql_mutex_lock(killing_thd->current_mutex);
2268 10166 mysql_cond_broadcast(killing_thd->current_cond);
2269 10166 mysql_mutex_unlock(killing_thd->current_mutex);
2270 }
2271 19546 mysql_mutex_unlock(&killing_thd->LOCK_current_cond);
2272 }
2273 19556 mysql_mutex_unlock(&killing_thd->LOCK_thd_data);
2274 }
2275 };
2276
2277 /**
2278 This class implements callback function used by close_connections()
2279 to close vio connection for all thds in thd list
2280 */
2281 class Call_close_conn : public Do_THD_Impl {
2282 public:
2283 10103 Call_close_conn(bool server_shutdown) : is_server_shutdown(server_shutdown) {}
2284
2285 3787 void operator()(THD *closing_thd) override {
2286
2/2
✓ Branch 0 taken 3262 times.
✓ Branch 1 taken 525 times.
3787 if (closing_thd->get_protocol()->connection_alive()) {
2287
1/2
✓ Branch 0 taken 3262 times.
✗ Branch 1 not taken.
3262 LEX_CSTRING main_sctx_user = closing_thd->m_main_security_ctx.user();
2288
9/18
✓ Branch 0 taken 3262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3262 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3262 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3262 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3262 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3262 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3262 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3262 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3262 times.
✗ Branch 17 not taken.
3262 LogErr(WARNING_LEVEL, ER_FORCE_CLOSE_THREAD, my_progname,
2289 (long)closing_thd->thread_id(),
2290 (main_sctx_user.length ? main_sctx_user.str : ""));
2291 /*
2292 Do not generate MYSQL_AUDIT_CONNECTION_DISCONNECT event, when closing
2293 thread close sessions. Each session will generate DISCONNECT event by
2294 itself.
2295 */
2296
1/2
✓ Branch 0 taken 3262 times.
✗ Branch 1 not taken.
3262 close_connection(closing_thd, 0, is_server_shutdown, false);
2297 }
2298 3787 }
2299
2300 private:
2301 bool is_server_shutdown;
2302 };
2303
2304 10103 static void close_connections(void) {
2305
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 DBUG_TRACE;
2306
4/6
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1507 times.
✓ Branch 3 taken 8596 times.
✓ Branch 4 taken 1507 times.
✗ Branch 5 not taken.
10103 (void)RUN_HOOK(server_state, before_server_shutdown, (nullptr));
2307
2308
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 Per_thread_connection_handler::kill_blocked_pthreads();
2309
2310 10103 uint dump_thread_count = 0;
2311 10103 uint dump_thread_kill_retries = 8;
2312
2313 // Close listeners.
2314
2/2
✓ Branch 0 taken 9817 times.
✓ Branch 1 taken 286 times.
10103 if (mysqld_socket_acceptor != nullptr)
2315
1/2
✓ Branch 0 taken 9817 times.
✗ Branch 1 not taken.
9817 mysqld_socket_acceptor->close_listener();
2316 #ifdef _WIN32
2317 if (named_pipe_acceptor != NULL) named_pipe_acceptor->close_listener();
2318
2319 if (shared_mem_acceptor != NULL) shared_mem_acceptor->close_listener();
2320 #endif
2321
2322 /*
2323 First signal all threads that it's time to die
2324 This will give the threads some time to gracefully abort their
2325 statements and inform their clients that the server is about to die.
2326 */
2327
2328 10103 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
2329
8/16
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10103 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10103 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10103 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10103 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10103 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 10103 times.
✗ Branch 15 not taken.
10103 LogErr(INFORMATION_LEVEL, ER_DEPART_WITH_GRACE,
2330 static_cast<int>(thd_manager->get_thd_count()));
2331
2332 10103 Set_kill_conn set_kill_conn;
2333
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 thd_manager->do_for_all_thd(&set_kill_conn);
2334
8/16
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10103 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10103 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10103 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10103 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10103 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 10103 times.
✗ Branch 15 not taken.
10103 LogErr(INFORMATION_LEVEL, ER_SHUTTING_DOWN_SLAVE_THREADS);
2335
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 end_slave();
2336
2337
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 9934 times.
10103 if (set_kill_conn.get_dump_thread_count()) {
2338 /*
2339 Replication dump thread should be terminated after the clients are
2340 terminated. Wait for few more seconds for other sessions to end.
2341 */
2342
5/6
✓ Branch 0 taken 1521 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1352 times.
✓ Branch 3 taken 169 times.
✓ Branch 4 taken 1352 times.
✓ Branch 5 taken 169 times.
1521 while (thd_manager->get_thd_count() > dump_thread_count &&
2343 dump_thread_kill_retries) {
2344
1/2
✓ Branch 0 taken 1352 times.
✗ Branch 1 not taken.
1352 sleep(1);
2345 1352 dump_thread_kill_retries--;
2346 }
2347 169 set_kill_conn.set_dump_thread_flag();
2348
1/2
✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
169 thd_manager->do_for_all_thd(&set_kill_conn);
2349 }
2350
2351 // Disable the event scheduler
2352
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 Events::stop();
2353
2354
3/4
✓ Branch 0 taken 4932 times.
✓ Branch 1 taken 5171 times.
✓ Branch 2 taken 4932 times.
✗ Branch 3 not taken.
10103 if (thd_manager->get_thd_count() > 0) sleep(2); // Give threads time to die
2355
2356 /*
2357 Force remaining threads to die by closing the connection to the client
2358 This will ensure that threads that are waiting for a command from the
2359 client on a blocking read call are aborted.
2360 */
2361
2362
8/16
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10103 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10103 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10103 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10103 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10103 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 10103 times.
✗ Branch 15 not taken.
10103 LogErr(INFORMATION_LEVEL, ER_DISCONNECTING_REMAINING_CLIENTS,
2363 static_cast<int>(thd_manager->get_thd_count()));
2364
2365 10103 Call_close_conn call_close_conn(true);
2366
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 thd_manager->do_for_all_thd(&call_close_conn);
2367
2368
4/6
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1507 times.
✓ Branch 3 taken 8596 times.
✓ Branch 4 taken 1507 times.
✗ Branch 5 not taken.
10103 (void)RUN_HOOK(server_state, after_server_shutdown, (nullptr));
2369
2370 /*
2371 All threads have now been aborted. Stop event scheduler thread
2372 after aborting all client connections, otherwise user may
2373 start/stop event scheduler after Events::deinit() deallocates
2374 scheduler object(static member in Events class)
2375 */
2376
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 Events::deinit();
2377
3/8
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10103 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
10103 DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)",
2378 thd_manager->get_thd_count()));
2379
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 thd_manager->wait_till_no_thd();
2380 /*
2381 Connection threads might take a little while to go down after removing from
2382 global thread list. Give it some time.
2383 */
2384
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 Connection_handler_manager::wait_till_no_connection();
2385
2386
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 delete_slave_info_objects();
2387
3/8
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10103 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
10103 DBUG_PRINT("quit", ("close_connections thread"));
2388 10103 }
2389
2390 58 bool signal_restart_server() {
2391
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 56 times.
58 if (!is_mysqld_managed()) {
2392 2 my_error(ER_RESTART_SERVER_FAILED, MYF(0),
2393 "mysqld is not managed by supervisor process");
2394 2 return true;
2395 }
2396
2397 #ifdef _WIN32
2398 if (!SetEvent(hEventRestart)) {
2399 LogErr(ERROR_LEVEL, ER_SET_EVENT_FAILED, GetLastError());
2400 my_error(ER_RESTART_SERVER_FAILED, MYF(0), "Internal operation failure");
2401 return true;
2402 }
2403 #else
2404
2405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (pthread_kill(signal_thread_id.thread, SIGUSR2)) {
2406 DBUG_PRINT("error", ("Got error %d from pthread_kill", errno));
2407 my_error(ER_RESTART_SERVER_FAILED, MYF(0), "Internal operation failure");
2408 return true;
2409 }
2410 #endif
2411 56 return false;
2412 }
2413
2414 9756 void kill_mysql(void) {
2415
1/2
✓ Branch 0 taken 9756 times.
✗ Branch 1 not taken.
9756 DBUG_TRACE;
2416
2417
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9752 times.
9756 if (!mysqld_server_started) {
2418 4 mysqld_process_must_end_at_startup = true;
2419 4 return;
2420 }
2421 #if defined(_WIN32)
2422 {
2423 if (!SetEvent(hEventShutdown)) {
2424 DBUG_PRINT("error", ("Got error: %ld from SetEvent", GetLastError()));
2425 }
2426 /*
2427 or:
2428 HANDLE hEvent=OpenEvent(0, false, "MySqlShutdown");
2429 SetEvent(hEventShutdown);
2430 CloseHandle(hEvent);
2431 */
2432 }
2433 #else
2434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9752 times.
9752 if (pthread_kill(signal_thread_id.thread, SIGTERM)) {
2435 DBUG_PRINT("error", ("Got error %d from pthread_kill",
2436 errno)); /* purecov: inspected */
2437 }
2438 #endif
2439
5/8
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9752 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 9751 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
9752 DBUG_PRINT("quit", ("After pthread_kill"));
2440
2/2
✓ Branch 0 taken 9752 times.
✓ Branch 1 taken 4 times.
9756 }
2441
2442 696 static void unireg_abort(int exit_code) {
2443
1/2
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
696 DBUG_TRACE;
2444
2445
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 420 times.
696 if (errno) {
2446
1/2
✓ Branch 0 taken 276 times.
✗ Branch 1 not taken.
276 sysd::notify("ERRNO=", errno, "\n");
2447 }
2448
2449
5/6
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 395 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 281 times.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
696 if (opt_initialize && exit_code && !opt_validate_config)
2450
12/20
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 20 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 20 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 10 times.
✓ Branch 17 taken 10 times.
✓ Branch 18 taken 20 times.
✗ Branch 19 not taken.
20 LogErr(ERROR_LEVEL,
2451 mysql_initialize_directory_freshly_created
2452 ? ER_DATA_DIRECTORY_UNUSABLE_DELETABLE
2453 : ER_DATA_DIRECTORY_UNUSABLE,
2454 mysql_real_data_home);
2455
2456 // At this point it does not make sense to buffer more messages.
2457 // Just flush what we have and write directly to stderr.
2458
1/2
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
696 flush_error_log_messages();
2459
2460
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 682 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
696 if (opt_help) usage();
2461
2462 bool daemon_launcher_quiet =
2463
5/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 692 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
699 (IF_WIN(false, opt_daemonize) && !mysqld::runtime::is_daemon() &&
2464
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 !is_help_or_validate_option());
2465
2466
12/20
✓ Branch 0 taken 693 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 388 times.
✓ Branch 3 taken 305 times.
✓ Branch 4 taken 388 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 388 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 388 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 388 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 388 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 388 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 388 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 388 times.
✗ Branch 19 not taken.
696 if (!daemon_launcher_quiet && exit_code) LogErr(ERROR_LEVEL, ER_ABORTING);
2467
2468
1/2
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
696 mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN,
2469 MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_ABORT, exit_code);
2470 #ifndef _WIN32
2471
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 406 times.
696 if (signal_thread_id.thread != 0) {
2472 // Make sure the signal thread isn't blocked when we are trying to exit.
2473
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 server_components_initialized();
2474
2475 290 pthread_kill(signal_thread_id.thread, SIGTERM);
2476
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 my_thread_join(&signal_thread_id, nullptr);
2477 }
2478 696 signal_thread_id.thread = 0;
2479
2480
3/4
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 695 times.
696 if (mysqld::runtime::is_daemon()) {
2481
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mysqld::runtime::signal_parent(pipe_write_fd, 0);
2482 }
2483 #endif
2484
7/8
✓ Branch 0 taken 677 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 674 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 289 times.
✓ Branch 5 taken 385 times.
✓ Branch 6 taken 696 times.
✗ Branch 7 not taken.
985 clean_up(!is_help_or_validate_option() && !daemon_launcher_quiet &&
2485
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 280 times.
289 (exit_code || !opt_initialize)); /* purecov: inspected */
2486
3/8
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 696 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
696 DBUG_PRINT("quit", ("done with cleanup in unireg_abort"));
2487 696 mysqld_exit(exit_code);
2488 }
2489
2490 33 void clean_up_mysqld_mutexes() { clean_up_mutexes(); }
2491
2492 10491 static void mysqld_exit(int exit_code) {
2493
4/6
✓ Branch 0 taken 10491 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10435 times.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 56 times.
10491 assert((exit_code >= MYSQLD_SUCCESS_EXIT && exit_code <= MYSQLD_ABORT_EXIT) ||
2494 exit_code == MYSQLD_RESTART_EXIT);
2495 10491 mysql_audit_finalize();
2496 10491 Srv_session::module_deinit();
2497 10491 delete_optimizer_cost_module();
2498 10491 clean_up_mutexes();
2499
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 10257 times.
10491 my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
2500 10491 destroy_error_log();
2501 10491 log_error_read_log_exit();
2502 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
2503 10491 shutdown_performance_schema();
2504 #endif
2505
2506 #ifdef WITH_LOCK_ORDER
2507 LO_cleanup();
2508 #endif
2509
2510 #if defined(_WIN32)
2511 if (hEventShutdown) CloseHandle(hEventShutdown);
2512 close_service_status_pipe_in_mysqld();
2513 #endif // _WIN32
2514
2515 10491 exit(exit_code); /* purecov: inspected */
2516 }
2517
2518 /**
2519 GTID cleanup destroys objects and reset their pointer.
2520 Function is reentrant.
2521 */
2522 10524 void gtid_server_cleanup() {
2523
2/2
✓ Branch 0 taken 10469 times.
✓ Branch 1 taken 55 times.
10524 if (gtid_state != nullptr) {
2524
1/2
✓ Branch 0 taken 10469 times.
✗ Branch 1 not taken.
10469 delete gtid_state;
2525 10469 gtid_state = nullptr;
2526 }
2527
2/2
✓ Branch 0 taken 10469 times.
✓ Branch 1 taken 55 times.
10524 if (global_sid_map != nullptr) {
2528
1/2
✓ Branch 0 taken 10469 times.
✗ Branch 1 not taken.
10469 delete global_sid_map;
2529 10469 global_sid_map = nullptr;
2530 }
2531
2/2
✓ Branch 0 taken 10469 times.
✓ Branch 1 taken 55 times.
10524 if (global_sid_lock != nullptr) {
2532
1/2
✓ Branch 0 taken 10469 times.
✗ Branch 1 not taken.
10469 delete global_sid_lock;
2533 10469 global_sid_lock = nullptr;
2534 }
2535
2/2
✓ Branch 0 taken 10469 times.
✓ Branch 1 taken 55 times.
10524 if (gtid_table_persistor != nullptr) {
2536
1/2
✓ Branch 0 taken 10469 times.
✗ Branch 1 not taken.
10469 delete gtid_table_persistor;
2537 10469 gtid_table_persistor = nullptr;
2538 }
2539 10524 }
2540
2541 /**
2542 GTID initialization.
2543
2544 @return true if allocation does not succeed
2545 false if OK
2546 */
2547 12087 bool gtid_server_init() {
2548 12087 global_gtid_mode.set(
2549 static_cast<Gtid_mode::value_type>(Gtid_mode::sysvar_mode));
2550 12087 bool res = (!(global_sid_lock = new Checkable_rwlock(
2551 #ifdef HAVE_PSI_INTERFACE
2552 key_rwlock_global_sid_lock
2553 #endif
2554
1/2
✓ Branch 0 taken 12087 times.
✗ Branch 1 not taken.
12087 )) ||
2555
2/4
✓ Branch 0 taken 12087 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12087 times.
✗ Branch 3 not taken.
12087 !(global_sid_map = new Sid_map(global_sid_lock)) ||
2556
3/6
✓ Branch 0 taken 12087 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12087 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12087 times.
✗ Branch 5 not taken.
36261 !(gtid_state = new Gtid_state(global_sid_lock, global_sid_map)) ||
2557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12087 times.
12087 !(gtid_table_persistor = new Gtid_table_persistor()));
2558
2559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12087 times.
12087 if (res) {
2560 gtid_server_cleanup();
2561 }
2562 12087 return res;
2563 }
2564
2565 // Free connection acceptors
2566 10491 static void free_connection_acceptors() {
2567
2/2
✓ Branch 0 taken 9833 times.
✓ Branch 1 taken 658 times.
10491 delete mysqld_socket_acceptor;
2568 10491 mysqld_socket_acceptor = nullptr;
2569
2570 #ifdef _WIN32
2571 delete named_pipe_acceptor;
2572 named_pipe_acceptor = NULL;
2573 delete shared_mem_acceptor;
2574 shared_mem_acceptor = NULL;
2575 #endif
2576 10491 }
2577
2578 10509 static void clean_up(bool print_message) {
2579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10509 times.
10509 DBUG_PRINT("exit", ("clean_up"));
2580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10509 times.
10509 if (cleanup_done++) return; /* purecov: inspected */
2581
2582 10509 ha_pre_dd_shutdown();
2583 10491 dd::shutdown();
2584
2585 10491 Events::deinit();
2586 10491 stop_handle_manager();
2587
2588 10491 memcached_shutdown();
2589
2590 10491 release_keyring_handles();
2591 10491 keyring_lockable_deinit();
2592
2593 /*
2594 make sure that handlers finish up
2595 what they have that is dependent on the binlog
2596 */
2597
5/8
✓ Branch 0 taken 10189 times.
✓ Branch 1 taken 302 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10189 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 10189 times.
✓ Branch 7 taken 302 times.
10491 if (print_message && (!is_help_or_validate_option() || opt_verbose))
2598
7/14
✓ Branch 0 taken 10189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10189 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10189 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10189 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10189 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10189 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10189 times.
✗ Branch 13 not taken.
10189 LogErr(INFORMATION_LEVEL, ER_BINLOG_END);
2599 10491 ha_binlog_end(current_thd);
2600
2601 10491 injector::free_instance();
2602 10491 mysql_bin_log.cleanup();
2603
2604 10491 udf_load_service.deinit();
2605
2/2
✓ Branch 0 taken 10154 times.
✓ Branch 1 taken 337 times.
10491 delete rpl_source_io_monitor;
2606 10491 rpl_source_io_monitor = nullptr;
2607
2/2
✓ Branch 0 taken 10154 times.
✓ Branch 1 taken 337 times.
10491 delete rpl_acf_configuration_handler;
2608 10491 rpl_acf_configuration_handler = nullptr;
2609
2610
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 10459 times.
10491 if (use_slave_mask) bitmap_free(&slave_error_mask);
2611 10491 my_tz_free();
2612 10491 servers_free(true);
2613 10491 acl_free(true);
2614 10491 grant_free();
2615 10491 hostname_cache_free();
2616 10491 range_optimizer_free();
2617 10491 item_func_sleep_free();
2618 10491 lex_free(); /* Free some memory */
2619 10491 item_create_cleanup();
2620
2/2
✓ Branch 0 taken 10144 times.
✓ Branch 1 taken 347 times.
10491 if (!opt_noacl) udf_unload_udfs();
2621 10491 table_def_start_shutdown();
2622 10491 delegates_shutdown();
2623 10491 plugin_shutdown();
2624 10491 gtid_server_cleanup(); // after plugin_shutdown
2625 10491 delete_optimizer_cost_module();
2626 10491 ha_end();
2627
2/2
✓ Branch 0 taken 622 times.
✓ Branch 1 taken 9869 times.
10491 if (tc_log) {
2628 622 tc_log->close();
2629 622 tc_log = nullptr;
2630 }
2631
2632
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10473 times.
10491 if (dd::upgrade_57::in_progress()) delete_dictionary_tablespace();
2633
2634 10491 Recovered_xa_transactions::destroy();
2635 10491 delegates_destroy();
2636 10491 xa::Transaction_cache::dispose();
2637 10491 MDL_context_backup_manager::destroy();
2638 10491 table_def_free();
2639 10491 mdl_destroy();
2640 10491 key_caches.delete_elements();
2641 10491 multi_keycache_free();
2642 10491 query_logger.cleanup();
2643 10491 free_tmpdir(&mysql_tmpdir_list);
2644 10491 my_free(opt_bin_logname);
2645 10491 free_max_user_conn();
2646 10491 free_global_user_stats();
2647 10491 free_global_client_stats();
2648 10491 free_global_thread_stats();
2649 10491 free_global_table_stats();
2650 10491 free_global_index_stats();
2651
1/2
✓ Branch 0 taken 10491 times.
✗ Branch 1 not taken.
10491 delete binlog_filter;
2652 10491 rpl_channel_filters.clean_up();
2653 10491 end_ssl();
2654 10491 vio_end();
2655 10491 u_cleanup();
2656 #if defined(ENABLED_DEBUG_SYNC)
2657 /* End the debug sync facility. See debug_sync.cc. */
2658 10491 debug_sync_end();
2659 #endif /* defined(ENABLED_DEBUG_SYNC) */
2660
2661 10491 delete_pid_file(MYF(0));
2662
2663
5/6
✓ Branch 0 taken 10189 times.
✓ Branch 1 taken 302 times.
✓ Branch 2 taken 10156 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 10156 times.
✗ Branch 5 not taken.
10491 if (print_message && my_default_lc_messages && server_start_time)
2664
7/14
✓ Branch 0 taken 10156 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10156 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10156 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10156 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10156 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10156 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10156 times.
✗ Branch 13 not taken.
10156 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_COMPLETE, my_progname,
2665 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
2666 10491 cleanup_errmsgs();
2667
2668 10491 sysd::notify("STATUS=Server shutdown complete");
2669
2670 10491 free_connection_acceptors();
2671 10491 Connection_handler_manager::destroy_instance();
2672
2673
6/6
✓ Branch 0 taken 10472 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 10172 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 10172 times.
✓ Branch 5 taken 319 times.
10491 if (!is_help_or_validate_option() && !opt_initialize)
2674 10172 resourcegroups::Resource_group_mgr::destroy_instance();
2675 10491 mysql_client_plugin_deinit();
2676
2677 10491 Global_THD_manager::destroy_instance();
2678
2679 10491 my_free(const_cast<char *>(log_bin_basename));
2680 10491 my_free(const_cast<char *>(log_bin_index));
2681 10491 my_free(const_cast<char *>(relay_log_basename));
2682 10491 my_free(const_cast<char *>(relay_log_index));
2683 10491 free_list(opt_early_plugin_load_list_ptr);
2684 10491 free_list(opt_plugin_load_list_ptr);
2685
2686 /*
2687 Is this the best place for components deinit? It may be changed when new
2688 dependencies are discovered, possibly being divided into separate points
2689 where all dependencies are still ok.
2690 */
2691 10491 log_error_stage_set(LOG_ERROR_STAGE_SHUTTING_DOWN);
2692 10491 log_builtins_error_stack(LOG_ERROR_SERVICES_DEFAULT, false, nullptr);
2693 #ifdef HAVE_PSI_THREAD_INTERFACE
2694
6/6
✓ Branch 0 taken 10472 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 10172 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 10172 times.
✓ Branch 5 taken 319 times.
10491 if (!is_help_or_validate_option() && !opt_initialize) {
2695 10172 unregister_pfs_notification_service();
2696 10172 unregister_pfs_resource_group_service();
2697 }
2698 #endif
2699 10491 deinit_tls_psi_keys();
2700 10491 deinitialize_manifest_file_components();
2701 10491 component_infrastructure_deinit();
2702 /*
2703 component unregister_variable() api depends on system_variable_hash.
2704 component_infrastructure_deinit() interns calls the deinit function
2705 of components which are loaded, and the deinit functions can have
2706 the component system unregister_ variable() api's, hence we need
2707 to call the sys_var_end() after component_infrastructure_deinit()
2708 */
2709 10491 sys_var_end();
2710 10491 free_status_vars();
2711
2712 10491 finish_client_errs();
2713 10491 deinit_errmessage(); // finish server errs
2714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10491 times.
10491 DBUG_PRINT("quit", ("Error messages freed"));
2715
2716
2/2
✓ Branch 0 taken 10422 times.
✓ Branch 1 taken 69 times.
10491 if (have_statement_timeout == SHOW_OPTION_YES) my_timer_deinitialize();
2717
2718 10491 have_statement_timeout = SHOW_OPTION_DISABLED;
2719
2720 10491 persisted_variables_cache.cleanup();
2721
2722 10491 udf_deinit_globals();
2723 /*
2724 The following lines may never be executed as the main thread may have
2725 killed us
2726 */
2727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10491 times.
10491 DBUG_PRINT("quit", ("done with cleanup"));
2728 } /* clean_up */
2729
2730 10524 static void clean_up_mutexes() {
2731 10524 mysql_mutex_destroy(&LOCK_log_throttle_qni);
2732 10524 mysql_mutex_destroy(&LOCK_status);
2733 10524 mysql_mutex_destroy(&LOCK_manager);
2734 10524 mysql_mutex_destroy(&LOCK_crypt);
2735 10524 mysql_mutex_destroy(&LOCK_user_conn);
2736 10524 mysql_rwlock_destroy(&LOCK_sys_init_connect);
2737 10524 mysql_rwlock_destroy(&LOCK_sys_init_replica);
2738 10524 mysql_mutex_destroy(&LOCK_global_system_variables);
2739 10524 mysql_rwlock_destroy(&LOCK_system_variables_hash);
2740 10524 mysql_mutex_destroy(&LOCK_uuid_generator);
2741 10524 mysql_mutex_destroy(&LOCK_sql_rand);
2742 10524 mysql_mutex_destroy(&LOCK_prepared_stmt_count);
2743 10524 mysql_mutex_destroy(&LOCK_replica_list);
2744 10524 mysql_mutex_destroy(&LOCK_sql_replica_skip_counter);
2745 10524 mysql_mutex_destroy(&LOCK_replica_net_timeout);
2746 10524 mysql_mutex_destroy(&LOCK_replica_trans_dep_tracker);
2747 10524 mysql_mutex_destroy(&LOCK_error_messages);
2748 10524 mysql_mutex_destroy(&LOCK_default_password_lifetime);
2749 10524 mysql_mutex_destroy(&LOCK_mandatory_roles);
2750 10524 mysql_mutex_destroy(&LOCK_server_started);
2751 10524 mysql_cond_destroy(&COND_server_started);
2752 10524 mysql_mutex_destroy(&LOCK_reset_gtid_table);
2753 10524 mysql_mutex_destroy(&LOCK_compress_gtid_table);
2754 10524 mysql_cond_destroy(&COND_compress_gtid_table);
2755 10524 mysql_mutex_destroy(&LOCK_collect_instance_log);
2756 10524 mysql_mutex_destroy(&LOCK_password_history);
2757 10524 mysql_mutex_destroy(&LOCK_password_reuse_interval);
2758 10524 mysql_cond_destroy(&COND_manager);
2759 #ifdef _WIN32
2760 mysql_cond_destroy(&COND_handler_count);
2761 mysql_mutex_destroy(&LOCK_handler_count);
2762 mysql_rwlock_destroy(&LOCK_named_pipe_full_access_group);
2763 #endif
2764 #ifndef _WIN32
2765 10524 mysql_cond_destroy(&COND_socket_listener_active);
2766 10524 mysql_mutex_destroy(&LOCK_socket_listener_active);
2767 10524 mysql_cond_destroy(&COND_start_signal_handler);
2768 10524 mysql_mutex_destroy(&LOCK_start_signal_handler);
2769 #endif
2770 10524 mysql_mutex_destroy(&LOCK_keyring_operations);
2771 10524 mysql_mutex_destroy(&LOCK_tls_ctx_options);
2772 10524 mysql_mutex_destroy(&LOCK_rotate_binlog_master_key);
2773 10524 mysql_mutex_destroy(&LOCK_global_user_client_stats);
2774 10524 mysql_mutex_destroy(&LOCK_global_table_stats);
2775 10524 mysql_mutex_destroy(&LOCK_global_index_stats);
2776 10524 mysql_rwlock_destroy(&LOCK_consistent_snapshot);
2777 10524 mysql_mutex_destroy(&LOCK_admin_tls_ctx_options);
2778 10524 mysql_mutex_destroy(&LOCK_partial_revokes);
2779 10524 mysql_mutex_destroy(&LOCK_authentication_policy);
2780 10524 mysql_mutex_destroy(&LOCK_global_conn_mem_limit);
2781 10524 }
2782
2783 /****************************************************************************
2784 ** Init IP and UNIX socket
2785 ****************************************************************************/
2786
2787 /* Initialise proxy protocol. */
2788 11468 static void set_proxy() {
2789
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 11441 times.
11472 if (opt_disable_networking) return;
2790
2791 struct st_vio_network net;
2792
2793 /* Check for special case '*'. */
2794
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11437 times.
11441 if (strcmp(my_proxy_protocol_networks, "*") == 0) {
2795 4 memset(&net, 0, sizeof(net));
2796 4 net.family = AF_INET;
2797 4 vio_proxy_protocol_add(net);
2798 4 net.family = AF_INET6;
2799 4 vio_proxy_protocol_add(net);
2800 4 return;
2801 }
2802
2803 11437 const char *p = my_proxy_protocol_networks;
2804
2805 while (1) {
2806 /* jump spaces. */
2807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11454 times.
11454 while (*p == ' ') p++;
2808
2/2
✓ Branch 0 taken 11426 times.
✓ Branch 1 taken 28 times.
11455 if (*p == '\0') break;
2809 28 const char *start = p;
2810
2811 /* look for separator */
2812
7/8
✓ Branch 0 taken 423 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 403 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 397 times.
✓ Branch 7 taken 6 times.
425 while (*p != ',' && *p != '/' && *p != ' ' && *p != '\0') p++;
2813
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
28 if (p - start > INET6_ADDRSTRLEN) {
2814
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
2815 "Too long network in 'proxy_protocol_networks' "
2816 "directive.");
2817
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
2818 }
2819 char buffer[INET6_ADDRSTRLEN + 1 + 3 + 1];
2820 27 memcpy(buffer, start, p - start);
2821 27 buffer[p - start] = '\0';
2822
2823 /* Try to convert to ipv4. */
2824
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 17 times.
27 if (inet_pton(AF_INET, buffer, &net.addr.in)) net.family = AF_INET;
2825
2826 /* Try to convert to ipv6. */
2827
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
17 else if (inet_pton(AF_INET6, buffer, &net.addr.in6))
2828 12 net.family = AF_INET6;
2829
2830 else {
2831
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 sql_print_error(
2832 "Bad network '%s' in 'proxy_protocol_networks' "
2833 "directive.",
2834 buffer);
2835
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5 unireg_abort(1);
2836 }
2837
2838 /* Look for network. */
2839 unsigned bits;
2840
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
22 if (*p == '/') {
2841
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
20 if (!my_isdigit(&my_charset_bin, *++p)) {
2842
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
2843 "Missing network prefix in 'proxy_protocol_networks' "
2844 "directive.");
2845
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
2846 }
2847 19 start = p;
2848 19 bits = 0;
2849
4/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 1 times.
58 while (my_isdigit(&my_charset_bin, *p) && p - start < 3)
2850 39 bits = bits * 10 + *p++ - '0';
2851
2852 /* Check bits value. */
2853
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
19 if (net.family == AF_INET && bits > 32) {
2854
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
2855 "Bad IPv4 mask in 'proxy_protocol_networks' "
2856 "directive.");
2857
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
2858 }
2859
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10 times.
18 if (net.family == AF_INET6 && bits > 128) {
2860
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
2861 "Bad IPv6 mask in 'proxy_protocol_networks' "
2862 "directive.");
2863
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
2864 }
2865 } else {
2866
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (net.family == AF_INET)
2867 1 bits = 32;
2868 else {
2869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(net.family == AF_INET6);
2870 1 bits = 128;
2871 }
2872 }
2873
2874 /* Build binary mask. */
2875
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 11 times.
19 if (net.family == AF_INET) {
2876 /* Process IPv4 mask. */
2877
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (bits == 0)
2878 2 net.mask.in.s_addr = 0x00000000;
2879
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 else if (bits == 32)
2880 2 net.mask.in.s_addr = 0xffffffff;
2881 else
2882 4 net.mask.in.s_addr = ~((0x80000000 >> (bits - 1)) - 1);
2883 8 net.mask.in.s_addr = htonl(net.mask.in.s_addr);
2884
2885 /* Apply mask */
2886 8 struct in_addr check = net.addr.in;
2887 8 check.s_addr &= net.mask.in.s_addr;
2888
2889 /* Check network. */
2890
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (check.s_addr != net.addr.in.s_addr)
2891
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_warning(
2892 "The network mask hides a part of the address for "
2893 "'%s/%d' in 'proxy_protocol_networks' directive.",
2894 buffer, bits);
2895 } else {
2896 /* Process IPv6 mask */
2897 11 memset(&net.mask.in6, 0, sizeof(net.mask.in6));
2898
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9 times.
11 if (bits > 0 && bits < 32) {
2899 1 net.mask.in6.s6_addr32[0] = ~((0x80000000 >> (bits - 1)) - 1);
2900
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 } else if (bits == 32) {
2901 1 net.mask.in6.s6_addr32[0] = 0xffffffff;
2902
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
9 } else if (bits > 32 && bits <= 64) {
2903 2 net.mask.in6.s6_addr32[0] = 0xffffffff;
2904 2 net.mask.in6.s6_addr32[1] =
2905
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 (bits == 64) ? 0xffffffff : ~((0x80000000 >> (bits - 32 - 1)) - 1);
2906
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
7 } else if (bits > 64 && bits <= 96) {
2907 3 net.mask.in6.s6_addr32[0] = 0xffffffff;
2908 3 net.mask.in6.s6_addr32[1] = 0xffffffff;
2909 3 net.mask.in6.s6_addr32[2] =
2910
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 (bits == 96) ? 0xffffffff : ~((0x80000000 >> (bits - 64 - 1)) - 1);
2911
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 } else if (bits > 96) {
2912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 assert(bits <= 128);
2913 3 net.mask.in6.s6_addr32[0] = 0xffffffff;
2914 3 net.mask.in6.s6_addr32[1] = 0xffffffff;
2915 3 net.mask.in6.s6_addr32[2] = 0xffffffff;
2916 3 net.mask.in6.s6_addr32[3] =
2917
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 (bits == 128) ? 0xffffffff : ~((0x80000000 >> (bits - 96 - 1)) - 1);
2918 }
2919
2920 11 net.mask.in6.s6_addr32[0] = htonl(net.mask.in6.s6_addr32[0]);
2921 11 net.mask.in6.s6_addr32[1] = htonl(net.mask.in6.s6_addr32[1]);
2922 11 net.mask.in6.s6_addr32[2] = htonl(net.mask.in6.s6_addr32[2]);
2923 11 net.mask.in6.s6_addr32[3] = htonl(net.mask.in6.s6_addr32[3]);
2924
2925 /* Apply mask */
2926 11 struct in6_addr check = net.addr.in6;
2927 11 check.s6_addr32[0] &= net.mask.in6.s6_addr32[0];
2928 11 check.s6_addr32[1] &= net.mask.in6.s6_addr32[1];
2929 11 check.s6_addr32[2] &= net.mask.in6.s6_addr32[2];
2930 11 check.s6_addr32[3] &= net.mask.in6.s6_addr32[3];
2931
2932 /* Check network. */
2933
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if (memcmp(check.s6_addr, net.addr.in6.s6_addr, 16)) {
2934
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 sql_print_warning(
2935 "The network mask hides a part of the address for "
2936 "'%s/%d' in 'proxy_protocol_networks' directive.",
2937 buffer, bits);
2938 }
2939 }
2940
2941
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17 times.
19 if (*p != '\0' && *p != ',') {
2942
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Bad syntax in 'proxy_protocol_networks' directive.");
2943
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
2944 }
2945
2946 /* add network. */
2947 18 vio_proxy_protocol_add(net);
2948
2949 /* stop the parsing. */
2950
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if (*p == '\0') break;
2951 17 p++;
2952 17 }
2953 }
2954
2955 12072 static void set_ports() {
2956 char *env;
2957
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 11643 times.
12072 if (!mysqld_port &&
2958
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 345 times.
429 !opt_disable_networking) { // Get port if not from commandline
2959 84 mysqld_port = MYSQL_PORT;
2960
2961 /*
2962 if builder specifically requested a default port, use that
2963 (even if it coincides with our factory default).
2964 only if they didn't do we check /etc/services (and, failing
2965 on that, fall back to the factory default of 3306).
2966 either default can be overridden by the environment variable
2967 MYSQL_TCP_PORT, which in turn can be overridden with command
2968 line options.
2969 */
2970
2971 #if MYSQL_PORT_DEFAULT == 0
2972 struct servent *serv_ptr;
2973
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if ((serv_ptr = getservbyname("mysql", "tcp")))
2974 84 mysqld_port = ntohs((u_short)serv_ptr->s_port); /* purecov: inspected */
2975 #endif
2976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if ((env = getenv("MYSQL_TCP_PORT")))
2977 mysqld_port = (uint)atoi(env); /* purecov: inspected */
2978 }
2979
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 11721 times.
12072 if (!mysqld_unix_port) {
2980 #ifdef _WIN32
2981 mysqld_unix_port = (char *)MYSQL_NAMEDPIPE;
2982 #else
2983 351 mysqld_unix_port = MYSQL_UNIX_ADDR;
2984 #endif
2985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if ((env = getenv("MYSQL_UNIX_PORT")))
2986 mysqld_unix_port = env; /* purecov: inspected */
2987 }
2988 12072 }
2989
2990 #if !defined(_WIN32)
2991 /* Change to run as another user if started with --user */
2992
2993 12087 static PasswdValue check_user(const char *user) {
2994 12087 uid_t user_id = geteuid();
2995
2996 PasswdValue tmp_user_info =
2997
3/4
✓ Branch 0 taken 12069 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
12087 (user == nullptr ? PasswdValue{} : my_getpwnam(user));
2998
2999 // Don't bother if we aren't superuser
3000
1/2
✓ Branch 0 taken 12087 times.
✗ Branch 1 not taken.
12087 if (user_id) {
3001
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12069 times.
12087 if (user) {
3002 /* Don't give a warning, if real user is same as given with --user */
3003
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if ((tmp_user_info.IsVoid() || user_id != tmp_user_info.pw_uid))
3004
8/16
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
18 LogErr(WARNING_LEVEL, ER_USER_REQUIRES_ROOT);
3005 }
3006 12087 return PasswdValue{};
3007 }
3008 assert(user_id == 0); // we are running as root
3009
3010 if (!user) {
3011 if (!opt_initialize && !is_help_or_validate_option()) {
3012 LogErr(ERROR_LEVEL, ER_REALLY_RUN_AS_ROOT);
3013 unireg_abort(MYSQLD_ABORT_EXIT);
3014 }
3015 return PasswdValue{};
3016 }
3017 /* purecov: begin tested */
3018 if (!strcmp(user, "root"))
3019 return PasswdValue{}; // Avoid problem with dynamic libraries
3020
3021 if (tmp_user_info.IsVoid()) {
3022 // Allow a numeric uid to be used
3023 const char *pos;
3024 for (pos = user; my_isdigit(mysqld_charset, *pos); pos++)
3025 ;
3026 if (*pos) // Not numeric id
3027 goto err;
3028
3029 tmp_user_info = my_getpwuid(atoi(user));
3030 if (tmp_user_info.IsVoid()) goto err;
3031 }
3032 return tmp_user_info;
3033 /* purecov: end */
3034
3035 err:
3036 LogErr(ERROR_LEVEL, ER_USER_WHAT_USER, user);
3037 unireg_abort(MYSQLD_ABORT_EXIT);
3038
3039 return PasswdValue{};
3040 12087 }
3041
3042 namespace mysqld_funcs_unit_test {
3043 21 PasswdValue check_user_drv(const char *user) { return check_user(user); }
3044 } // namespace mysqld_funcs_unit_test
3045
3046 static void set_user(const char *user, const PasswdValue &user_info_arg) {
3047 /* purecov: begin tested */
3048 assert(user_info_arg.IsVoid() == false);
3049 #ifdef HAVE_INITGROUPS
3050 initgroups(user, user_info_arg.pw_gid);
3051 #endif
3052 if (setgid(user_info_arg.pw_gid) == -1) {
3053 LogErr(ERROR_LEVEL, ER_FAIL_SETGID, strerror(errno));
3054 unireg_abort(MYSQLD_ABORT_EXIT);
3055 }
3056 if (setuid(user_info_arg.pw_uid) == -1) {
3057 LogErr(ERROR_LEVEL, ER_FAIL_SETUID, strerror(errno));
3058 unireg_abort(MYSQLD_ABORT_EXIT);
3059 }
3060
3061 #ifdef HAVE_SYS_PRCTL_H
3062 if (test_flags & TEST_CORE_ON_SIGNAL) {
3063 /* inform kernel that process is dumpable */
3064 (void)prctl(PR_SET_DUMPABLE, 1);
3065 }
3066 #endif
3067
3068 /* purecov: end */
3069 }
3070
3071 static void set_effective_user(const PasswdValue &user_info_arg) {
3072 assert(user_info_arg.IsVoid() == false);
3073 if (setregid((gid_t)-1, user_info_arg.pw_gid) == -1) {
3074 LogErr(ERROR_LEVEL, ER_FAIL_SETREGID, strerror(errno));
3075 unireg_abort(MYSQLD_ABORT_EXIT);
3076 }
3077 if (setreuid((uid_t)-1, user_info_arg.pw_uid) == -1) {
3078 LogErr(ERROR_LEVEL, ER_FAIL_SETREUID, strerror(errno));
3079 unireg_abort(MYSQLD_ABORT_EXIT);
3080 }
3081 }
3082
3083 /** Change root user if started with @c --chroot . */
3084 static void set_root(const char *path) {
3085 if (chroot(path) == -1) {
3086 LogErr(ERROR_LEVEL, ER_FAIL_CHROOT, strerror(errno));
3087 unireg_abort(MYSQLD_ABORT_EXIT);
3088 }
3089 my_setwd("/", MYF(0));
3090 }
3091 #endif // !_WIN32
3092
3093 /**
3094 Check that an address value is a wildcard IP value,
3095 that is it has either the value 0.0.0.0 for IPv4 or the value ::1 in
3096 case IPv6, or has the specially treated symbol * as its value.
3097
3098 @param address_value Address value to check
3099 @param address_length Address length
3100
3101 @return true in case the address value is a wildcard value, else false.
3102 */
3103 11589 bool check_address_is_wildcard(const char *address_value,
3104 size_t address_length) {
3105 return
3106 // Wildcard is not allowed in case a comma separated list of
3107 // addresses is specified
3108 11589 native_strncasecmp(address_value, MY_BIND_ALL_ADDRESSES,
3109
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 6 times.
79 address_length) == 0 ||
3110 // The specially treated address :: is not allowed in case
3111 // a comma separated list of addresses is specified
3112 79 native_strncasecmp(address_value, ipv6_all_addresses, address_length) ==
3113
4/4
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 11510 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 68 times.
11668 0 ||
3114 // The specially treated address 0.0.0.0 is not allowed in case
3115 // a comma separated list of addresses is specified
3116 73 native_strncasecmp(address_value, ipv4_all_addresses, address_length) ==
3117 11589 0;
3118 }
3119
3120 /**
3121 Take a string representing host or ip address followed by
3122 optional delimiter '/' and namespace name and put address part
3123 and namespace part into corresponding output parameters.
3124
3125 @param begin_address_value start of a string containing an address value
3126 @param end_address_value pointer to an end of string containing
3127 an address value. Has the value nullptr in case
3128 address value not continue
3129 @param [out] address_value address value extracted from address string
3130 @param [out] network_namespace network namespace extracted from
3131 the address string value if any
3132
3133 @return false on success, true on address format error
3134 */
3135 11491 static bool parse_address_string(const char *begin_address_value,
3136 const char *end_address_value,
3137 std::string *address_value,
3138 std::string *network_namespace) {
3139 11491 const char *namespace_separator = strchr(begin_address_value, '/');
3140
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11491 times.
11491 if (namespace_separator != nullptr) {
3142 if (begin_address_value == namespace_separator)
3143 /*
3144 Parse error: there is no character before '/',
3145 that is missed address value
3146 */
3147 return true;
3148
3149 if (namespace_separator < end_address_value) {
3150 if (end_address_value - namespace_separator == 1)
3151 /*
3152 Parse error: there is no character immediately after '/',
3153 that is missed namespace name.
3154 */
3155 return true;
3156
3157 /*
3158 Found namespace delimiter. Extract namespace and address values
3159 */
3160 *address_value = std::string(begin_address_value, namespace_separator);
3161 *network_namespace =
3162 std::string(namespace_separator + 1, end_address_value);
3163 } else if (end_address_value != nullptr)
3164 /*
3165 This branch corresponds to the case when namespace separator is located
3166 after the last character of the address subvalue being processed.
3167 For example, if the following string '192.168.1.1,172.1.1.1/red'
3168 passed into the function create_bind_address_info_from_string(),
3169 then during handling of the address 192.168.1.1 search of '/'
3170 will return a position after the end of the sub string 192.168.1.1
3171 (in the next sub string 172.1.1.1/red) that should be ignored.
3172 */
3173 *address_value = std::string(begin_address_value, end_address_value);
3174 else {
3175 /*
3176 This branch corresponds to the case when namespace separator is located
3177 at the last part of address values. For example,
3178 this branch is executed during handling of the following value
3179 192.168.1.1,::1,::1/greeen for the option --bind-address.
3180 */
3181 *address_value = std::string(begin_address_value, namespace_separator);
3182 *network_namespace = std::string(namespace_separator + 1);
3183 if (*(namespace_separator + 1) == 0)
3184 /*
3185 Parse error: there is no character immediately
3186 after '/' - a namespace name missed.
3187 */
3188 return true;
3189 }
3190 } else {
3191 /*
3192 Regular address without network namespace found.
3193 */
3194 *address_value = end_address_value != nullptr
3195
8/14
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 11482 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11482 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11482 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 11482 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
22982 ? std::string(begin_address_value, end_address_value)
3196 11491 : std::string(begin_address_value);
3197 }
3198
3199 11491 return false;
3200 }
3201
3202 /**
3203 Parse a value of address sub string with checking of address string format,
3204 extract address part and namespace part of the address value, and store
3205 their values into the argument valid_bind_addresses.
3206
3207 @return false on success, true on address format error
3208 */
3209 11459 static bool create_bind_address_info_from_string(
3210 const char *begin_address_value, const char *end_address_value,
3211 std::list<Bind_address_info> *valid_bind_addresses) {
3212 11459 Bind_address_info bind_address_info;
3213 11459 std::string address_value, network_namespace;
3214
3215
2/4
✓ Branch 0 taken 11459 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11459 times.
11459 if (parse_address_string(begin_address_value, end_address_value,
3216 &address_value, &network_namespace))
3217 return true;
3218
3219
1/2
✓ Branch 0 taken 11459 times.
✗ Branch 1 not taken.
11459 if (network_namespace.empty())
3220
1/2
✓ Branch 0 taken 11459 times.
✗ Branch 1 not taken.
11459 bind_address_info = Bind_address_info(address_value);
3221 else {
3222 /*
3223 Wildcard value is not allowed in case network namespace specified
3224 for address value in the option bind-address.
3225 */
3226 if (check_address_is_wildcard(address_value.c_str(),
3227 address_value.length())) {
3228 LogErr(ERROR_LEVEL,
3229 ER_NETWORK_NAMESPACE_NOT_ALLOWED_FOR_WILDCARD_ADDRESS);
3230 return true;
3231 }
3232
3233 bind_address_info = Bind_address_info(address_value, network_namespace);
3234 }
3235
3236
1/2
✓ Branch 0 taken 11459 times.
✗ Branch 1 not taken.
11459 valid_bind_addresses->emplace_back(bind_address_info);
3237
3238 11459 return false;
3239 11459 }
3240
3241 /**
3242 Check acceptable value(s) of parameter bind-address
3243
3244 @param bind_address Value of the parameter bind-address
3245 @param[out] valid_bind_addresses List of addresses to listen and their
3246 corresponding network namespaces if set.
3247
3248 @return false on success, true on failure
3249 */
3250 11458 static bool check_bind_address_has_valid_value(
3251 const char *bind_address,
3252 std::list<Bind_address_info> *valid_bind_addresses) {
3253
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11456 times.
11458 if (strlen(bind_address) == 0)
3254 // Empty value for bind_address is an error
3255 2 return true;
3256
3257 11456 const char *comma_separator = strchr(bind_address, ',');
3258 11456 const char *begin_of_value = bind_address;
3259 11456 const bool multiple_bind_addresses = (comma_separator != nullptr);
3260
3261
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11455 times.
11456 if (comma_separator == begin_of_value)
3262 // Return an error if a value of bind_address begins with comma
3263 1 return true;
3264
3265
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11453 times.
11463 while (comma_separator != nullptr) {
3266 10 Bind_address_info bind_address_info;
3267 10 std::string address_value, network_namespace;
3268 /*
3269 Wildcard value is not allowed in case multi-addresses value specified
3270 for the option bind-address.
3271 */
3272
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (check_address_is_wildcard(begin_of_value,
3273
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 comma_separator - begin_of_value)) {
3274
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_WILDCARD_NOT_ALLOWED_FOR_MULTIADDRESS_BIND);
3275
3276 1 return true;
3277 }
3278
3279
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (create_bind_address_info_from_string(begin_of_value, comma_separator,
3280 valid_bind_addresses))
3281 return true;
3282
3283 9 begin_of_value = comma_separator + 1;
3284 9 comma_separator = strchr(begin_of_value, ',');
3285
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (comma_separator == begin_of_value)
3286 // Return an error if a value of bind_address has two adjacent commas
3287 1 return true;
3288
6/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
14 }
3289
3290 /*
3291 Wildcard value is not allowed in case multi-addresses value specified
3292 for the option bind-address.
3293 */
3294
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11448 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 11450 times.
11458 if (multiple_bind_addresses &&
3295
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 (check_address_is_wildcard(begin_of_value, strlen(begin_of_value)) ||
3296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 strlen(begin_of_value) == 0))
3297 3 return true;
3298
3299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11450 times.
11450 if (create_bind_address_info_from_string(begin_of_value, comma_separator,
3300 valid_bind_addresses))
3301 return true;
3302
3303 11450 return false;
3304 }
3305
3306 /**
3307 Check acceptable value(s) of the parameter admin-address
3308
3309 @param admin_bind_addr_str Value of the parameter admin-address
3310 @param[out] admin_address_info List of addresses to listen and their
3311 corresponding network namespaces if set.
3312
3313 @return false on success, true on failure
3314 */
3315 32 static bool check_admin_address_has_valid_value(
3316 const char *admin_bind_addr_str, Bind_address_info *admin_address_info) {
3317 32 std::string address_value, network_namespace;
3318
3319
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 if (parse_address_string(admin_bind_addr_str, nullptr, &address_value,
3320 &network_namespace))
3321 return true;
3322
3323
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 29 times.
32 if (check_address_is_wildcard(address_value.c_str(),
3324 address_value.length())) {
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!network_namespace.empty())
3326 LogErr(ERROR_LEVEL,
3327 ER_NETWORK_NAMESPACE_NOT_ALLOWED_FOR_WILDCARD_ADDRESS);
3328
3329 3 return true;
3330 }
3331
3332
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (network_namespace.empty())
3333
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 *admin_address_info = Bind_address_info(address_value);
3334 else
3335 *admin_address_info = Bind_address_info(address_value, network_namespace);
3336
3337 29 return false;
3338 32 }
3339
3340 11758 static bool network_init(void) {
3341
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 11468 times.
11758 if (opt_initialize) return false;
3342
3343
1/2
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
11468 set_proxy();
3344 #ifdef HAVE_SYS_UN_H
3345
2/4
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11458 times.
✗ Branch 3 not taken.
11458 std::string const unix_sock_name(mysqld_unix_port ? mysqld_unix_port : "");
3346 #else
3347 std::string const unix_sock_name("");
3348 #endif
3349
3350 11458 std::list<Bind_address_info> bind_addresses_info;
3351
3352
5/8
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 11431 times.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11458 times.
✗ Branch 7 not taken.
11458 if (!opt_disable_networking || unix_sock_name != "") {
3353
3/4
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 11450 times.
22916 if (my_bind_addr_str != nullptr &&
3354
3/4
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 11450 times.
11458 check_bind_address_has_valid_value(my_bind_addr_str,
3355 &bind_addresses_info)) {
3356
8/16
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
8 LogErr(ERROR_LEVEL, ER_INVALID_VALUE_OF_BIND_ADDRESSES, my_bind_addr_str);
3357 15 return true;
3358 }
3359
3360 11450 Bind_address_info admin_address_info;
3361
2/2
✓ Branch 0 taken 11423 times.
✓ Branch 1 taken 27 times.
11450 if (!opt_disable_networking) {
3362
4/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 11391 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 11420 times.
11455 if (my_admin_bind_addr_str != nullptr &&
3363
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 29 times.
32 check_admin_address_has_valid_value(my_admin_bind_addr_str,
3364 &admin_address_info)) {
3365
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_INVALID_ADMIN_ADDRESS, my_admin_bind_addr_str);
3366 3 return true;
3367 }
3368 /*
3369 Port 0 is interpreted by implementations of TCP protocol
3370 as a hint to find a first free port value to use and bind to it.
3371 On the other hand, the option mysqld_admin_port can be assigned
3372 the value 0 if a user specified a value that is out of allowable
3373 range of values. Therefore, to avoid a case when an operating
3374 system binds admin interface to am arbitrary selected port value,
3375 set it explicitly to the value MYSQL_ADMIN_PORT in case it has value 0.
3376 */
3377
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11419 times.
11420 if (mysqld_admin_port == 0) mysqld_admin_port = MYSQL_ADMIN_PORT;
3378 }
3379 Mysqld_socket_listener *mysqld_socket_listener = new (std::nothrow)
3380 Mysqld_socket_listener(bind_addresses_info, mysqld_port,
3381 admin_address_info, mysqld_admin_port,
3382 11447 admin_address_info.address.empty()
3383
2/2
✓ Branch 0 taken 11418 times.
✓ Branch 1 taken 29 times.
11447 ? false
3384 : listen_admin_interface_in_separate_thread,
3385
3/6
✓ Branch 0 taken 11447 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11447 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11447 times.
✗ Branch 5 not taken.
11447 back_log, mysqld_port_timeout, unix_sock_name);
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11447 times.
11447 if (mysqld_socket_listener == nullptr) return true;
3387
3388 11447 mysqld_socket_acceptor = new (std::nothrow)
3389
1/2
✓ Branch 0 taken 11447 times.
✗ Branch 1 not taken.
11447 Connection_acceptor<Mysqld_socket_listener>(mysqld_socket_listener);
3390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11447 times.
11447 if (mysqld_socket_acceptor == nullptr) {
3391 delete mysqld_socket_listener;
3392 mysqld_socket_listener = nullptr;
3393 return true;
3394 }
3395
3396
3/4
✓ Branch 0 taken 11447 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 11443 times.
11447 if (mysqld_socket_acceptor->init_connection_acceptor())
3397 4 return true; // mysqld_socket_acceptor would be freed in unireg_abort.
3398
3399
2/2
✓ Branch 0 taken 8682 times.
✓ Branch 1 taken 2761 times.
11443 if (report_port == 0) report_port = mysqld_port;
3400
3401
3/4
✓ Branch 0 taken 11416 times.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11416 times.
11443 if (!opt_disable_networking) assert(report_port != 0);
3402
2/2
✓ Branch 0 taken 11443 times.
✓ Branch 1 taken 7 times.
11450 }
3403 #ifdef _WIN32
3404 // Create named pipe
3405 if (opt_enable_named_pipe) {
3406 std::string pipe_name = mysqld_unix_port ? mysqld_unix_port : "";
3407
3408 named_pipe_listener = new (std::nothrow) Named_pipe_listener(&pipe_name);
3409 if (named_pipe_listener == NULL) return true;
3410
3411 named_pipe_acceptor = new (std::nothrow)
3412 Connection_acceptor<Named_pipe_listener>(named_pipe_listener);
3413 if (named_pipe_acceptor == NULL) {
3414 delete named_pipe_listener;
3415 named_pipe_listener = NULL;
3416 return true;
3417 }
3418
3419 if (named_pipe_acceptor->init_connection_acceptor())
3420 return true; // named_pipe_acceptor would be freed in unireg_abort.
3421 }
3422
3423 // Setup shared_memory acceptor
3424 if (opt_enable_shared_memory) {
3425 std::string shared_mem_base_name =
3426 shared_memory_base_name ? shared_memory_base_name : "";
3427
3428 Shared_mem_listener *shared_mem_listener =
3429 new (std::nothrow) Shared_mem_listener(&shared_mem_base_name);
3430 if (shared_mem_listener == NULL) return true;
3431
3432 shared_mem_acceptor = new (std::nothrow)
3433 Connection_acceptor<Shared_mem_listener>(shared_mem_listener);
3434 if (shared_mem_acceptor == NULL) {
3435 delete shared_mem_listener;
3436 shared_mem_listener = NULL;
3437 return true;
3438 }
3439
3440 if (shared_mem_acceptor->init_connection_acceptor())
3441 return true; // shared_mem_acceptor would be freed in unireg_abort.
3442 }
3443 #endif // _WIN32
3444 11443 return false;
3445 11458 }
3446
3447 #ifdef _WIN32
3448 static uint handler_count = 0;
3449
3450 static inline void decrement_handler_count() {
3451 mysql_mutex_lock(&LOCK_handler_count);
3452 handler_count--;
3453 mysql_cond_signal(&COND_handler_count);
3454 mysql_mutex_unlock(&LOCK_handler_count);
3455 }
3456
3457 extern "C" void *socket_conn_event_handler(void *arg) {
3458 my_thread_init();
3459
3460 Connection_acceptor<Mysqld_socket_listener> *conn_acceptor =
3461 static_cast<Connection_acceptor<Mysqld_socket_listener> *>(arg);
3462 conn_acceptor->connection_event_loop();
3463
3464 decrement_handler_count();
3465 my_thread_end();
3466 return 0;
3467 }
3468
3469 extern "C" void *named_pipe_conn_event_handler(void *arg) {
3470 my_thread_init();
3471
3472 Connection_acceptor<Named_pipe_listener> *conn_acceptor =
3473 static_cast<Connection_acceptor<Named_pipe_listener> *>(arg);
3474 conn_acceptor->connection_event_loop();
3475
3476 decrement_handler_count();
3477 my_thread_end();
3478 return 0;
3479 }
3480
3481 extern "C" void *shared_mem_conn_event_handler(void *arg) {
3482 my_thread_init();
3483
3484 Connection_acceptor<Shared_mem_listener> *conn_acceptor =
3485 static_cast<Connection_acceptor<Shared_mem_listener> *>(arg);
3486 conn_acceptor->connection_event_loop();
3487
3488 decrement_handler_count();
3489 my_thread_end();
3490 return 0;
3491 }
3492
3493 void setup_conn_event_handler_threads() {
3494 my_thread_handle hThread;
3495
3496 DBUG_TRACE;
3497
3498 if ((!have_tcpip || opt_disable_networking) && !opt_enable_shared_memory &&
3499 !opt_enable_named_pipe) {
3500 LogErr(ERROR_LEVEL, ER_WIN_LISTEN_BUT_HOW);
3501 unireg_abort(MYSQLD_ABORT_EXIT); // Will not return
3502 }
3503
3504 mysql_mutex_lock(&LOCK_handler_count);
3505 handler_count = 0;
3506
3507 if (opt_enable_named_pipe) {
3508 int error = mysql_thread_create(
3509 key_thread_handle_con_namedpipes, &hThread, &connection_attrib,
3510 named_pipe_conn_event_handler, named_pipe_acceptor);
3511 if (!error)
3512 handler_count++;
3513 else
3514 LogErr(WARNING_LEVEL, ER_CANT_CREATE_NAMED_PIPES_THREAD, error);
3515 }
3516
3517 if (have_tcpip && !opt_disable_networking) {
3518 int error = mysql_thread_create(
3519 key_thread_handle_con_sockets, &hThread, &connection_attrib,
3520 socket_conn_event_handler, mysqld_socket_acceptor);
3521 if (!error)
3522 handler_count++;
3523 else
3524 LogErr(WARNING_LEVEL, ER_CANT_CREATE_TCPIP_THREAD, error);
3525 }
3526
3527 if (opt_enable_shared_memory) {
3528 int error = mysql_thread_create(
3529 key_thread_handle_con_sharedmem, &hThread, &connection_attrib,
3530 shared_mem_conn_event_handler, shared_mem_acceptor);
3531 if (!error)
3532 handler_count++;
3533 else
3534 LogErr(WARNING_LEVEL, ER_CANT_CREATE_SHM_THREAD, error);
3535 }
3536
3537 // Block until all connection listener threads have exited.
3538 while (handler_count > 0)
3539 mysql_cond_wait(&COND_handler_count, &LOCK_handler_count);
3540 mysql_mutex_unlock(&LOCK_handler_count);
3541 }
3542
3543 /*
3544 On Windows, we use native SetConsoleCtrlHandler for handle events like Ctrl-C
3545 with graceful shutdown.
3546 Also, we do not use signal(), but SetUnhandledExceptionFilter instead - as it
3547 provides possibility to pass the exception to just-in-time debugger, collect
3548 dumps and potentially also the exception and thread context used to output
3549 callstack.
3550 */
3551
3552 static BOOL WINAPI console_event_handler(DWORD type) {
3553 DBUG_TRACE;
3554 if (type == CTRL_C_EVENT) {
3555 /*
3556 Do not shutdown before startup is finished and shutdown
3557 thread is initialized. Otherwise there is a race condition
3558 between main thread doing initialization and CTRL-C thread doing
3559 cleanup, which can result into crash.
3560 */
3561 if (hEventShutdown)
3562 kill_mysql();
3563 else
3564 LogErr(WARNING_LEVEL, ER_NOT_RIGHT_NOW);
3565 return true;
3566 }
3567 return false;
3568 }
3569
3570 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER
3571 #define DEBUGGER_ATTACH_TIMEOUT 120
3572 /*
3573 Wait for debugger to attach and break into debugger. If debugger is not
3574 attached, resume after timeout.
3575 */
3576 static void wait_for_debugger(int timeout_sec) {
3577 if (!IsDebuggerPresent()) {
3578 int i;
3579 printf("Waiting for debugger to attach, pid=%u\n", GetCurrentProcessId());
3580 fflush(stdout);
3581 for (i = 0; i < timeout_sec; i++) {
3582 Sleep(1000);
3583 if (IsDebuggerPresent()) {
3584 /* Break into debugger */
3585 __debugbreak();
3586 return;
3587 }
3588 }
3589 printf("pid=%u, debugger not attached after %d seconds, resuming\n",
3590 GetCurrentProcessId(), timeout_sec);
3591 fflush(stdout);
3592 }
3593 }
3594 #endif /* DEBUG_UNHANDLED_EXCEPTION_FILTER */
3595
3596 LONG WINAPI my_unhandler_exception_filter(EXCEPTION_POINTERS *ex_pointers) {
3597 static BOOL first_time = true;
3598 if (!first_time) {
3599 /*
3600 This routine can be called twice, typically
3601 when detaching in JIT debugger.
3602 Return EXCEPTION_EXECUTE_HANDLER to terminate process.
3603 */
3604 return EXCEPTION_EXECUTE_HANDLER;
3605 }
3606 first_time = false;
3607 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER
3608 /*
3609 Unfortunately there is no clean way to debug unhandled exception filters,
3610 as debugger does not stop there(also documented in MSDN)
3611 To overcome, one could put a MessageBox, but this will not work in service.
3612 Better solution is to print error message and sleep some minutes
3613 until debugger is attached
3614 */
3615 wait_for_debugger(DEBUGGER_ATTACH_TIMEOUT);
3616 #endif /* DEBUG_UNHANDLED_EXCEPTION_FILTER */
3617 __try {
3618 my_set_exception_pointers(ex_pointers);
3619 handle_fatal_signal(ex_pointers->ExceptionRecord->ExceptionCode);
3620 } __except (EXCEPTION_EXECUTE_HANDLER) {
3621 DWORD written;
3622 const char msg[] = "Got exception in exception handler!\n";
3623 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msg, sizeof(msg) - 1, &written,
3624 NULL);
3625 }
3626 /*
3627 Return EXCEPTION_CONTINUE_SEARCH to give JIT debugger
3628 (drwtsn32 or vsjitdebugger) possibility to attach,
3629 if JIT debugger is configured.
3630 Windows Error reporting might generate a dump here.
3631 */
3632 return EXCEPTION_CONTINUE_SEARCH;
3633 }
3634
3635 void my_init_signals() {
3636 if (opt_console) SetConsoleCtrlHandler(console_event_handler, true);
3637
3638 /* Avoid MessageBox()es*/
3639 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
3640 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
3641 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
3642 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
3643 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
3644 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
3645
3646 /*
3647 Do not use SEM_NOGPFAULTERRORBOX in the following SetErrorMode (),
3648 because it would prevent JIT debugger and Windows error reporting
3649 from working. We need WER or JIT-debugging, since our own unhandled
3650 exception filter is not guaranteed to work in all situation
3651 (like heap corruption or stack overflow)
3652 */
3653 SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS |
3654 SEM_NOOPENFILEERRORBOX);
3655 SetUnhandledExceptionFilter(my_unhandler_exception_filter);
3656 }
3657
3658 #else // !_WIN32
3659
3660 extern "C" {
3661 28970 static void empty_signal_handler(int sig [[maybe_unused]]) {}
3662 }
3663
3664 12142 void my_init_signals() {
3665
1/2
✓ Branch 0 taken 12142 times.
✗ Branch 1 not taken.
12142 DBUG_TRACE;
3666 struct sigaction sa;
3667 12142 (void)sigemptyset(&sa.sa_mask);
3668
3669
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 12122 times.
12142 if (!(test_flags & TEST_NO_STACKTRACE) ||
3670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 (test_flags & TEST_CORE_ON_SIGNAL)) {
3671 #ifdef HAVE_STACKTRACE
3672
1/2
✓ Branch 0 taken 12122 times.
✗ Branch 1 not taken.
12122 my_init_stacktrace();
3673 #endif
3674
3675
2/2
✓ Branch 0 taken 11594 times.
✓ Branch 1 taken 528 times.
12122 if (test_flags & TEST_CORE_ON_SIGNAL) {
3676 // Change limits so that we will get a core file.
3677 struct rlimit rl;
3678 11594 rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
3679
1/18
✗ Branch 0 not taken.
✓ Branch 1 taken 11594 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
11594 if (setrlimit(RLIMIT_CORE, &rl)) LogErr(WARNING_LEVEL, ER_CORE_VALUES);
3680 }
3681
3682 /*
3683 SA_RESETHAND resets handler action to default when entering handler.
3684 SA_NODEFER allows receiving the same signal during handler.
3685 E.g. SIGABRT during our signal handler will dump core (default action).
3686 */
3687 12122 sa.sa_flags = SA_RESETHAND | SA_NODEFER;
3688 12122 sa.sa_handler = handle_fatal_signal;
3689 // Treat these as fatal and handle them.
3690 12122 sigaction(SIGABRT, &sa, nullptr);
3691 12122 sigaction(SIGFPE, &sa, nullptr);
3692 // Handle these as well, except for ASAN/UBSAN builds:
3693 // we let sanitizer runtime handle them instead.
3694 #if defined(HANDLE_FATAL_SIGNALS)
3695 12122 sigaction(SIGBUS, &sa, nullptr);
3696 12122 sigaction(SIGILL, &sa, nullptr);
3697 12122 sigaction(SIGSEGV, &sa, nullptr);
3698 #endif
3699 }
3700
3701 // Ignore SIGPIPE
3702 12142 sa.sa_flags = 0;
3703 12142 sa.sa_handler = SIG_IGN;
3704 12142 (void)sigaction(SIGPIPE, &sa, nullptr);
3705
3706 // SIGALRM is used to interrupt the socket listener.
3707 12142 sa.sa_handler = empty_signal_handler;
3708 12142 (void)sigaction(SIGALRM, &sa, nullptr);
3709
3710 // Fix signals if ignored by parents (can happen on Mac OS X).
3711 12142 sa.sa_handler = SIG_DFL;
3712 12142 (void)sigaction(SIGTERM, &sa, nullptr);
3713 12142 (void)sigaction(SIGHUP, &sa, nullptr);
3714 12142 (void)sigaction(SIGUSR1, &sa, nullptr);
3715
3716 12142 (void)sigemptyset(&mysqld_signal_mask);
3717 /*
3718 Block SIGQUIT, SIGHUP, SIGTERM, SIGUSR1 and SIGUSR2.
3719 The signal handler thread does sigwait() on these.
3720 */
3721 12142 (void)sigaddset(&mysqld_signal_mask, SIGQUIT);
3722 12142 (void)sigaddset(&mysqld_signal_mask, SIGHUP);
3723 12142 (void)sigaddset(&mysqld_signal_mask, SIGTERM);
3724 12142 (void)sigaddset(&mysqld_signal_mask, SIGTSTP);
3725 12142 (void)sigaddset(&mysqld_signal_mask, SIGUSR1);
3726 12142 (void)sigaddset(&mysqld_signal_mask, SIGUSR2);
3727 /*
3728 Block SIGINT unless debugging to prevent Ctrl+C from causing
3729 unclean shutdown of the server.
3730 */
3731
2/2
✓ Branch 0 taken 12107 times.
✓ Branch 1 taken 35 times.
12142 if (!(test_flags & TEST_SIGINT)) (void)sigaddset(&mysqld_signal_mask, SIGINT);
3732 12142 pthread_sigmask(SIG_SETMASK, &mysqld_signal_mask, nullptr);
3733 12142 }
3734
3735 11691 static void start_signal_handler() {
3736 int error;
3737 my_thread_attr_t thr_attr;
3738
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 DBUG_TRACE;
3739
3740 11691 (void)my_thread_attr_init(&thr_attr);
3741 11691 (void)pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
3742 11691 (void)my_thread_attr_setdetachstate(&thr_attr, MY_THREAD_CREATE_JOINABLE);
3743
3744 11691 size_t guardize = 0;
3745 11691 (void)pthread_attr_getguardsize(&thr_attr, &guardize);
3746 #if defined(__ia64__) || defined(__ia64)
3747 /*
3748 Peculiar things with ia64 platforms - it seems we only have half the
3749 stack size in reality, so we have to double it here
3750 */
3751 guardize = my_thread_stack_size;
3752 #endif
3753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11691 times.
11691 if (0 !=
3754 11691 my_thread_attr_setstacksize(&thr_attr, my_thread_stack_size + guardize)) {
3755 assert(false);
3756 }
3757
3758 /*
3759 Set main_thread_id so that SIGTERM/SIGQUIT/SIGKILL/SIGUSR2 can interrupt
3760 the socket listener successfully.
3761 */
3762 11691 main_thread_id = my_thread_self();
3763
3764
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_mutex_lock(&LOCK_start_signal_handler);
3765
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
11691 if ((error = mysql_thread_create(key_thread_signal_hand, &signal_thread_id,
3766 &thr_attr, signal_hand, nullptr))) {
3767 LogErr(ERROR_LEVEL, ER_CANT_CREATE_INTERRUPT_THREAD, error, errno);
3768 flush_error_log_messages();
3769 exit(MYSQLD_ABORT_EXIT);
3770 }
3771
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_cond_wait(&COND_start_signal_handler, &LOCK_start_signal_handler);
3772
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_mutex_unlock(&LOCK_start_signal_handler);
3773
3774 11691 (void)my_thread_attr_destroy(&thr_attr);
3775 11691 }
3776
3777 /** This thread handles SIGTERM, SIGQUIT, SIGHUP, SIGUSR1 and SIGUSR2 signals.
3778 */
3779 /* ARGSUSED */
3780 11691 extern "C" void *signal_hand(void *arg [[maybe_unused]]) {
3781
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 my_thread_init();
3782
3783 sigset_t set;
3784 11691 (void)sigemptyset(&set);
3785 11691 (void)sigaddset(&set, SIGTERM);
3786 11691 (void)sigaddset(&set, SIGQUIT);
3787 11691 (void)sigaddset(&set, SIGHUP);
3788 11691 (void)sigaddset(&set, SIGUSR1);
3789 11691 (void)sigaddset(&set, SIGUSR2);
3790
3791 /*
3792 Signal to start_signal_handler that we are ready.
3793 This works by waiting for start_signal_handler to free mutex,
3794 after which we signal it that we are ready.
3795 */
3796
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_mutex_lock(&LOCK_start_signal_handler);
3797
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_cond_broadcast(&COND_start_signal_handler);
3798
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 mysql_mutex_unlock(&LOCK_start_signal_handler);
3799
3800 /*
3801 Wait until that all server components have been successfully initialized.
3802 This step is mandatory since signal processing can be done safely only when
3803 all server components have been initialized.
3804 */
3805
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 server_components_init_wait();
3806 for (;;) {
3807 11702 int sig = 0;
3808 int rc;
3809 bool error;
3810 #ifdef __APPLE__
3811 while ((rc = sigwait(&set, &sig)) == EINTR) {
3812 }
3813 error = rc != 0;
3814 #else
3815 siginfo_t sig_info;
3816
6/8
✓ Branch 0 taken 10147 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 10114 times.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 33 times.
✓ Branch 7 taken 10114 times.
11735 while ((rc = sigwaitinfo(&set, &sig_info)) == -1 && errno == EINTR) {
3817 }
3818 10114 error = rc == -1;
3819
1/2
✓ Branch 0 taken 10114 times.
✗ Branch 1 not taken.
10114 if (!error) sig = sig_info.si_signo;
3820 #endif // __APPLE__
3821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10114 times.
10114 if (error)
3822 sql_print_error(
3823 "Fatal error in signal handling thread. sigwait/sigwaitinfo returned "
3824 "error %d\n. Exiting signal handler "
3825 "thread.",
3826 errno);
3827
3828
2/4
✓ Branch 0 taken 10114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10114 times.
10114 if (error || cleanup_done) {
3829 my_thread_end();
3830 my_thread_exit(nullptr); // Safety
3831 return nullptr; // Avoid compiler warnings
3832 }
3833
4/5
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 10047 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
10114 switch (sig) {
3834 56 case SIGUSR2:
3835 56 signal_hand_thr_exit_code = MYSQLD_RESTART_EXIT;
3836 #ifndef __APPLE__ // Mac OS doesn't have sigwaitinfo.
3837 // Log a note if mysqld is restarted via kill command.
3838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (sig_info.si_pid != getpid()) {
3839 sql_print_information(
3840 "Received signal SIGUSR2."
3841 " Restarting mysqld (Version %s)",
3842 server_version);
3843 }
3844 #endif // __APPLE__
3845 [[fallthrough]];
3846 case SIGTERM:
3847 case SIGQUIT:
3848 #ifndef __APPLE__ // Mac OS doesn't have sigwaitinfo.
3849
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10097 times.
10103 if (sig_info.si_pid != getpid())
3850
8/16
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
6 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_INFO, "<via user signal>",
3851 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
3852 #else
3853 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_INFO, "<via user signal>",
3854 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
3855 #endif // __APPLE__
3856 // Switch to the file log message processing.
3857
3/4
✓ Branch 0 taken 10102 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
10103 query_logger.set_handlers((log_output_options != LOG_NONE) ? LOG_FILE
3858 : LOG_NONE);
3859
3/8
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10103 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10103 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
10103 DBUG_PRINT("info",
3860 ("Got signal: %d connection_events_loop_aborted: %d", sig,
3861 connection_events_loop_aborted()));
3862
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 if (!connection_events_loop_aborted()) {
3863 // Mark abort for threads.
3864 10103 set_connection_events_loop_aborted(true);
3865 #ifdef HAVE_PSI_THREAD_INTERFACE
3866 // Delete the instrumentation for the signal thread.
3867
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 PSI_THREAD_CALL(delete_current_thread)();
3868 #endif /* HAVE_PSI_THREAD_INTERFACE */
3869 /*
3870 Kill the socket listener.
3871 The main thread will then set socket_listener_active= false,
3872 and wait for us to finish all the cleanup below.
3873 */
3874
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 mysql_mutex_lock(&LOCK_socket_listener_active);
3875
2/2
✓ Branch 0 taken 9813 times.
✓ Branch 1 taken 10103 times.
19916 while (socket_listener_active) {
3876
3/8
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9813 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9813 DBUG_PRINT("info", ("Killing socket listener"));
3877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (pthread_kill(main_thread_id, SIGALRM)) {
3878 assert(false);
3879 break;
3880 }
3881
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_cond_wait(&COND_socket_listener_active,
3882 &LOCK_socket_listener_active);
3883 }
3884
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 mysql_mutex_unlock(&LOCK_socket_listener_active);
3885
3886
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 close_connections();
3887 }
3888
1/2
✓ Branch 0 taken 10103 times.
✗ Branch 1 not taken.
10103 my_thread_end();
3889 10103 my_thread_exit(nullptr);
3890 return nullptr; // Avoid compiler warnings
3891 break;
3892 4 case SIGHUP:
3893
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!connection_events_loop_aborted()) {
3894 int not_used;
3895
5/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
4 DBUG_EXECUTE_IF("simulate_sighup_print_status", {
3896 printf("\nStatus information:\n\n");
3897 fflush(stdout);
3898 });
3899
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 handle_reload_request(
3900 nullptr,
3901 (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST | REFRESH_GRANT |
3902 REFRESH_THREADS | REFRESH_HOSTS),
3903 nullptr, &not_used); // Flush logs
3904 // Re-enable query logs after the options were reloaded.
3905
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 query_logger.set_handlers(log_output_options);
3906 }
3907 4 break;
3908 7 case SIGUSR1:
3909
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (!connection_events_loop_aborted()) {
3910 int not_used;
3911
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 handle_reload_request(
3912 nullptr,
3913 (REFRESH_ERROR_LOG | /**< Rotate only the error log */
3914 REFRESH_GENERAL_LOG | /**< Flush the general log */
3915 REFRESH_SLOW_LOG), /**< Flush the slow query log */
3916 nullptr, &not_used); // Flush logs
3917 // Re-enable query logs after the options were reloaded.
3918
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 query_logger.set_handlers(log_output_options);
3919 }
3920 7 break;
3921 default:
3922 break; /* purecov: tested */
3923 }
3924 11 }
3925 return nullptr; /* purecov: deadcode */
3926 }
3927
3928 #endif // !_WIN32
3929
3930 /**
3931 All global error messages are sent here where the first one is stored
3932 for the client.
3933 */
3934 /* ARGSUSED */
3935 extern "C" void my_message_sql(uint error, const char *str, myf MyFlags);
3936
3937 2357605 void my_message_sql(uint error, const char *str, myf MyFlags) {
3938
1/2
✓ Branch 0 taken 2357614 times.
✗ Branch 1 not taken.
2357605 THD *thd = current_thd;
3939
1/2
✓ Branch 0 taken 2357622 times.
✗ Branch 1 not taken.
2357614 DBUG_TRACE;
3940
5/8
✓ Branch 0 taken 2357623 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2357621 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2357605 times.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
2357622 DBUG_PRINT("error", ("error: %u message: '%s'", error, str));
3941
3942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2357620 times.
2357620 assert(str != nullptr);
3943 /*
3944 An error should have a valid error number (!= 0), so it can be caught
3945 in stored procedures by SQL exception handlers.
3946 Calling my_error() with error == 0 is a bug.
3947 Remaining known places to fix:
3948 - storage/myisam/mi_create.c, my_printf_error()
3949 TODO:
3950 assert(error != 0);
3951 */
3952
3953
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2357619 times.
2357620 if (error == 0) {
3954 /* At least, prevent new abuse ... */
3955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(strncmp(str, "MyISAM table", 12) == 0);
3956 1 error = ER_UNKNOWN_ERROR;
3957 }
3958
3959 /* Caller wishes to inform client, and one is attached. */
3960
2/2
✓ Branch 0 taken 2357271 times.
✓ Branch 1 taken 349 times.
2357620 if (thd) {
3961 2357271 (void)thd->raise_condition(error, nullptr, Sql_condition::SL_ERROR, str,
3962
1/2
✓ Branch 0 taken 2357268 times.
✗ Branch 1 not taken.
2357271 MyFlags & ME_FATALERROR);
3963
3964 /*
3965 Now for an argument check.
3966 We're asserting after rather than before raising the
3967 condition to make the culprit easier to track down.
3968
3969 Messages intended for the error-log are in the range
3970 starting at ER_SERVER_RANGE_START (error_code 10,000);
3971 messages intended for sending to a client are in the
3972 range below ER_SERVER_RANGE_START. If a message is to
3973 be sent to both a client and the error log, it must
3974 be added twice (once in each range), and two separate
3975 calls (e.g. my_error() and LogErr()) must be added to
3976 the code.
3977
3978 Only error-codes from the client range should be seen
3979 in this if(). If your patch asserts here, one of two
3980 things probably happened:
3981
3982 - You added a new message to messages_to_error_log.txt:
3983 The message was added to the server range, but code
3984 was added that tries to send the message to a client
3985 (my_error(), push_warning_printf(), etc.).
3986
3987 => Move the new message to messages_to_clients.txt.
3988 The copied message should be added at the end of
3989 the range for the lowest server version you're adding
3990 the message to.
3991 Rebuild the server; rerun your test.
3992
3993 - You used an existing message:
3994 The existing message is intended for use with
3995 the error-log (it appears in messages_to_error_log.txt),
3996 but the new code tries to send it to a client (my_error(),
3997 push_warning_printf(), etc.).
3998
3999 => Copy the existing message to messages_to_clients.txt.
4000 - The copied message should be added at the end of
4001 the range for the lowest server version you're adding
4002 the message to.
4003 - The copied message will need its own symbol;
4004 if in doubt, call the copy of ER_EXAMPLE_MESSAGE
4005 ER_DA_EXAMPLE_MESSAGE (as this version is for use
4006 with the diagnostics area).
4007 Then make sure that your new code references
4008 this new symbol when it sends the message
4009 to a client.
4010 Rebuild the server; rerun your test.
4011
4012 We'll assert this here (rather than in raise_condition) as
4013 SQL's SIGNAL command also calls raise_condition, and SIGNAL
4014 is currently allowed to set any error-code (regardless of
4015 range). SIGNALing an error-code from the error-log range
4016 will not result in writing to that log to prevent abuse.
4017 */
4018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2357268 times.
2357268 assert(error < ER_SERVER_RANGE_START);
4019 }
4020
4021 /* When simulating OOM, skip writing to error log to avoid mtr errors */
4022
3/4
✓ Branch 0 taken 2357619 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 2357607 times.
2357617 DBUG_EXECUTE_IF("simulate_out_of_memory", return;);
4023
4024 /*
4025 Caller wishes to send to both the client and the error-log.
4026 This is legacy behaviour that is no longer legal as errors flagged
4027 to a client and those sent to the error-log are in different
4028 numeric ranges now. If you own code that does this, see about
4029 updating it by splitting it into two calls, one sending status
4030 to the client, the other sending it to the error-log using
4031 LogErr() and friends.
4032 */
4033
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2357605 times.
2357607 if (MyFlags & ME_ERRORLOG) {
4034 /*
4035 We've removed most uses of ME_ERRORLOG in the server.
4036 This leaves three possible cases, in which we'll rewrite
4037 the error-code from one in the client-range to one in
4038 the error-log range here:
4039
4040 - EE_OUTOFMEMORY: Correct to ER_SERVER_OUT_OF_RESOURCES so
4041 mysys can remain logger-agnostic.
4042
4043 - HA_* range: Correct to catch-all ER_SERVER_HANDLER_ERROR.
4044
4045 - otherwise: Flag as using info from the diagnostics area
4046 (ER_ERROR_INFO_FROM_DA). This is a failsafe;
4047 if your code triggers it, your code is probably
4048 wrong.
4049 */
4050
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((error == EE_OUTOFMEMORY) || (error == HA_ERR_OUT_OF_MEM))
4051 error = ER_SERVER_OUT_OF_RESOURCES;
4052
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (error <= HA_ERR_LAST)
4053 2 error = ER_SERVER_HANDLER_ERROR;
4054
4055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (error < ER_SERVER_RANGE_START)
4056 LogEvent()
4057 .type(LOG_TYPE_ERROR)
4058 .prio(ERROR_LEVEL)
4059 .errcode(ER_ERROR_INFO_FROM_DA)
4060 .lookup(ER_ERROR_INFO_FROM_DA, error, str);
4061 else
4062
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 LogEvent()
4063
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .type(LOG_TYPE_ERROR)
4064
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .prio(ERROR_LEVEL)
4065
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .errcode(error)
4066
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .verbatim(str);
4067
4068 /*
4069 This is no longer supported behaviour except for the cases
4070 outlined above, so flag anything else in debug builds!
4071 (We're bailing after rather than before printing to make the
4072 culprit easier to track down.)
4073 */
4074
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 assert((error == ER_FEATURE_NOT_AVAILABLE) ||
4075 (error >= ER_SERVER_RANGE_START));
4076 }
4077
4078 /*
4079 Caller wishes to send to client, but none is attached, so we send
4080 to error-log instead.
4081 */
4082
2/2
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 2357257 times.
2357605 else if (!thd) {
4083
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
696 LogEvent()
4084
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 .type(LOG_TYPE_ERROR)
4085
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 .subsys(LOG_SUBSYSTEM_TAG)
4086
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 .prio(ERROR_LEVEL)
4087
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
✓ Branch 2 taken 348 times.
✗ Branch 3 not taken.
348 .errcode((error < ER_SERVER_RANGE_START)
4088 ? ER_SERVER_NO_SESSION_TO_SEND_TO
4089 : error)
4090
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 .lookup(ER_SERVER_NO_SESSION_TO_SEND_TO, error, str);
4091 }
4092
2/2
✓ Branch 0 taken 2357607 times.
✓ Branch 1 taken 12 times.
2357619 }
4093
4094 extern "C" void *my_str_malloc_mysqld(size_t size);
4095 extern "C" void my_str_free_mysqld(void *ptr);
4096 extern "C" void *my_str_realloc_mysqld(void *ptr, size_t size);
4097
4098 13 void *my_str_malloc_mysqld(size_t size) {
4099 13 return my_malloc(key_memory_my_str_malloc, size, MYF(MY_FAE));
4100 }
4101
4102 13 void my_str_free_mysqld(void *ptr) { my_free(ptr); }
4103
4104 void *my_str_realloc_mysqld(void *ptr, size_t size) {
4105 return my_realloc(key_memory_my_str_malloc, ptr, size, MYF(MY_FAE));
4106 }
4107
4108 const char *load_default_groups[] = {
4109 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
4110 "mysql_cluster",
4111 #endif
4112 "mysqld", "server", MYSQL_BASE_VERSION, nullptr, nullptr};
4113
4114 #if defined(_WIN32)
4115 static const int load_default_groups_sz =
4116 sizeof(load_default_groups) / sizeof(load_default_groups[0]);
4117 #endif
4118
4119 /**
4120 This function is used to check for stack overrun for pathological
4121 cases of regular expressions and 'like' expressions.
4122 The call to current_thd is quite expensive, so we try to avoid it
4123 for the normal cases.
4124 The size of each stack frame for the wildcmp() routines is ~128 bytes,
4125 so checking *every* recursive call is not necessary.
4126 */
4127 extern "C" {
4128 144720298 static int check_enough_stack_size(int recurse_level) {
4129 uchar stack_top;
4130
1/2
✓ Branch 0 taken 144720298 times.
✗ Branch 1 not taken.
144720298 if (recurse_level % 16 != 0) return 0;
4131
4132 THD *my_thd = current_thd;
4133 if (my_thd != nullptr)
4134 return check_stack_overrun(my_thd, STACK_MIN_SIZE * 4, &stack_top);
4135 return 0;
4136 }
4137 } // extern "C"
4138
4139 SHOW_VAR com_status_vars[] = {
4140 {"admin_commands", (char *)offsetof(System_status_var, com_other),
4141 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4142 {"assign_to_keycache",
4143 (char *)offsetof(System_status_var,
4144 com_stat[(uint)SQLCOM_ASSIGN_TO_KEYCACHE]),
4145 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4146 {"alter_db",
4147 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_DB]),
4148 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4149 {"alter_event",
4150 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_EVENT]),
4151 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4152 {"alter_function",
4153 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_FUNCTION]),
4154 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4155 {"alter_instance",
4156 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_INSTANCE]),
4157 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4158 {"alter_procedure",
4159 (char *)offsetof(System_status_var,
4160 com_stat[(uint)SQLCOM_ALTER_PROCEDURE]),
4161 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4162 {"alter_resource_group",
4163 (char *)offsetof(System_status_var,
4164 com_stat[(uint)SQLCOM_ALTER_RESOURCE_GROUP]),
4165 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4166 {"alter_server",
4167 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_SERVER]),
4168 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4169 {"alter_table",
4170 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_TABLE]),
4171 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4172 {"alter_tablespace",
4173 (char *)offsetof(System_status_var,
4174 com_stat[(uint)SQLCOM_ALTER_TABLESPACE]),
4175 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4176 {"alter_user",
4177 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_USER]),
4178 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4179 {"alter_user_default_role",
4180 (char *)offsetof(System_status_var,
4181 com_stat[(uint)SQLCOM_ALTER_USER_DEFAULT_ROLE]),
4182 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4183 {"analyze",
4184 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ANALYZE]),
4185 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4186 {"begin", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_BEGIN]),
4187 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4188 {"binlog",
4189 (char *)offsetof(System_status_var,
4190 com_stat[(uint)SQLCOM_BINLOG_BASE64_EVENT]),
4191 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4192 {"call_procedure",
4193 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CALL]),
4194 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4195 {"change_db",
4196 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_DB]),
4197 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4198 {"change_master",
4199 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_MASTER]),
4200 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4201 {"change_repl_filter",
4202 (char *)offsetof(System_status_var,
4203 com_stat[(uint)SQLCOM_CHANGE_REPLICATION_FILTER]),
4204 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4205 {"change_replication_source",
4206 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_MASTER]),
4207 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4208 {"check", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHECK]),
4209 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4210 {"checksum",
4211 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHECKSUM]),
4212 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4213 {"clone", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CLONE]),
4214 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4215 {"commit",
4216 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_COMMIT]),
4217 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4218 {"create_compression_dictionary",
4219 (char *)offsetof(System_status_var,
4220 com_stat[(uint)SQLCOM_CREATE_COMPRESSION_DICTIONARY]),
4221 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4222 {"create_db",
4223 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_DB]),
4224 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4225 {"create_event",
4226 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_EVENT]),
4227 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4228 {"create_function",
4229 (char *)offsetof(System_status_var,
4230 com_stat[(uint)SQLCOM_CREATE_SPFUNCTION]),
4231 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4232 {"create_index",
4233 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_INDEX]),
4234 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4235 {"create_procedure",
4236 (char *)offsetof(System_status_var,
4237 com_stat[(uint)SQLCOM_CREATE_PROCEDURE]),
4238 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4239 {"create_role",
4240 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_ROLE]),
4241 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4242 {"create_server",
4243 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_SERVER]),
4244 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4245 {"create_table",
4246 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_TABLE]),
4247 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4248 {"create_resource_group",
4249 (char *)offsetof(System_status_var,
4250 com_stat[(uint)SQLCOM_CREATE_RESOURCE_GROUP]),
4251 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4252 {"create_trigger",
4253 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_TRIGGER]),
4254 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4255 {"create_udf",
4256 (char *)offsetof(System_status_var,
4257 com_stat[(uint)SQLCOM_CREATE_FUNCTION]),
4258 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4259 {"create_user",
4260 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_USER]),
4261 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4262 {"create_view",
4263 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_VIEW]),
4264 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4265 {"create_spatial_reference_system",
4266 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_SRS]),
4267 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4268 {"dealloc_sql",
4269 (char *)offsetof(System_status_var,
4270 com_stat[(uint)SQLCOM_DEALLOCATE_PREPARE]),
4271 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4272 {"delete",
4273 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DELETE]),
4274 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4275 {"delete_multi",
4276 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DELETE_MULTI]),
4277 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4278 {"do", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DO]),
4279 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4280 {"drop_compression_dictionary",
4281 (char *)offsetof(System_status_var,
4282 com_stat[(uint)SQLCOM_DROP_COMPRESSION_DICTIONARY]),
4283 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4284 {"drop_db",
4285 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_DB]),
4286 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4287 {"drop_event",
4288 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_EVENT]),
4289 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4290 {"drop_function",
4291 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_FUNCTION]),
4292 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4293 {"drop_index",
4294 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_INDEX]),
4295 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4296 {"drop_procedure",
4297 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_PROCEDURE]),
4298 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4299 {"drop_resource_group",
4300 (char *)offsetof(System_status_var,
4301 com_stat[(uint)SQLCOM_DROP_RESOURCE_GROUP]),
4302 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4303 {"drop_role",
4304 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_ROLE]),
4305 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4306 {"drop_server",
4307 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_SERVER]),
4308 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4309 {"drop_spatial_reference_system",
4310 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_SRS]),
4311 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4312 {"drop_table",
4313 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_TABLE]),
4314 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4315 {"drop_trigger",
4316 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_TRIGGER]),
4317 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4318 {"drop_user",
4319 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_USER]),
4320 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4321 {"drop_view",
4322 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_VIEW]),
4323 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4324 {"empty_query",
4325 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EMPTY_QUERY]),
4326 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4327 {"execute_sql",
4328 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EXECUTE]),
4329 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4330 {"explain_other",
4331 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EXPLAIN_OTHER]),
4332 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4333 {"flush", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_FLUSH]),
4334 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4335 {"get_diagnostics",
4336 (char *)offsetof(System_status_var,
4337 com_stat[(uint)SQLCOM_GET_DIAGNOSTICS]),
4338 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4339 {"grant", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_GRANT]),
4340 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4341 {"grant_roles",
4342 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_GRANT_ROLE]),
4343 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4344 {"ha_close",
4345 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_CLOSE]),
4346 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4347 {"ha_open",
4348 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_OPEN]),
4349 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4350 {"ha_read",
4351 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_READ]),
4352 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4353 {"help", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HELP]),
4354 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4355 {"import",
4356 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_IMPORT]),
4357 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4358 {"insert",
4359 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSERT]),
4360 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4361 {"insert_select",
4362 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSERT_SELECT]),
4363 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4364 {"install_component",
4365 (char *)offsetof(System_status_var,
4366 com_stat[(uint)SQLCOM_INSTALL_COMPONENT]),
4367 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4368 {"install_plugin",
4369 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSTALL_PLUGIN]),
4370 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4371 {"kill", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_KILL]),
4372 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4373 {"load", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOAD]),
4374 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4375 {"lock_instance",
4376 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOCK_INSTANCE]),
4377 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4378 {"lock_tables",
4379 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOCK_TABLES]),
4380 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4381 {"lock_tables_for_backup",
4382 (char *)offsetof(System_status_var,
4383 com_stat[(uint)SQLCOM_LOCK_TABLES_FOR_BACKUP]),
4384 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4385 {"optimize",
4386 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_OPTIMIZE]),
4387 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4388 {"preload_keys",
4389 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PRELOAD_KEYS]),
4390 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4391 {"prepare_sql",
4392 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PREPARE]),
4393 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4394 {"purge", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PURGE]),
4395 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4396 {"purge_before_date",
4397 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PURGE_BEFORE]),
4398 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4399 {"release_savepoint",
4400 (char *)offsetof(System_status_var,
4401 com_stat[(uint)SQLCOM_RELEASE_SAVEPOINT]),
4402 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4403 {"rename_table",
4404 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RENAME_TABLE]),
4405 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4406 {"rename_user",
4407 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RENAME_USER]),
4408 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4409 {"repair",
4410 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPAIR]),
4411 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4412 {"replace",
4413 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPLACE]),
4414 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4415 {"replace_select",
4416 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPLACE_SELECT]),
4417 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4418 {"reset", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESET]),
4419 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4420 {"resignal",
4421 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESIGNAL]),
4422 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4423 {"restart",
4424 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESTART_SERVER]),
4425 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4426 {"revoke",
4427 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE]),
4428 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4429 {"revoke_all",
4430 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE_ALL]),
4431 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4432 {"revoke_roles",
4433 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE_ROLE]),
4434 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4435 {"rollback",
4436 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ROLLBACK]),
4437 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4438 {"rollback_to_savepoint",
4439 (char *)offsetof(System_status_var,
4440 com_stat[(uint)SQLCOM_ROLLBACK_TO_SAVEPOINT]),
4441 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4442 {"savepoint",
4443 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SAVEPOINT]),
4444 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4445 {"select",
4446 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SELECT]),
4447 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4448 {"set_option",
4449 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_OPTION]),
4450 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4451 {"set_password",
4452 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_PASSWORD]),
4453 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4454 {"set_resource_group",
4455 (char *)offsetof(System_status_var,
4456 com_stat[(uint)SQLCOM_SET_RESOURCE_GROUP]),
4457 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4458 {"set_role",
4459 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_ROLE]),
4460 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4461 {"signal",
4462 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SIGNAL]),
4463 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4464 {"show_binlog_events",
4465 (char *)offsetof(System_status_var,
4466 com_stat[(uint)SQLCOM_SHOW_BINLOG_EVENTS]),
4467 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4468 {"show_binlogs",
4469 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_BINLOGS]),
4470 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4471 {"show_charsets",
4472 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CHARSETS]),
4473 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4474 {"show_client_statistics",
4475 (char *)offsetof(System_status_var,
4476 com_stat[(uint)SQLCOM_SHOW_CLIENT_STATS]),
4477 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4478 {"show_collations",
4479 (char *)offsetof(System_status_var,
4480 com_stat[(uint)SQLCOM_SHOW_COLLATIONS]),
4481 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4482 {"show_create_db",
4483 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CREATE_DB]),
4484 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4485 {"show_create_event",
4486 (char *)offsetof(System_status_var,
4487 com_stat[(uint)SQLCOM_SHOW_CREATE_EVENT]),
4488 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4489 {"show_create_func",
4490 (char *)offsetof(System_status_var,
4491 com_stat[(uint)SQLCOM_SHOW_CREATE_FUNC]),
4492 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4493 {"show_create_proc",
4494 (char *)offsetof(System_status_var,
4495 com_stat[(uint)SQLCOM_SHOW_CREATE_PROC]),
4496 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4497 {"show_create_table",
4498 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CREATE]),
4499 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4500 {"show_create_trigger",
4501 (char *)offsetof(System_status_var,
4502 com_stat[(uint)SQLCOM_SHOW_CREATE_TRIGGER]),
4503 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4504 {"show_databases",
4505 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_DATABASES]),
4506 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4507 {"show_engine_logs",
4508 (char *)offsetof(System_status_var,
4509 com_stat[(uint)SQLCOM_SHOW_ENGINE_LOGS]),
4510 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4511 {"show_engine_mutex",
4512 (char *)offsetof(System_status_var,
4513 com_stat[(uint)SQLCOM_SHOW_ENGINE_MUTEX]),
4514 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4515 {"show_engine_status",
4516 (char *)offsetof(System_status_var,
4517 com_stat[(uint)SQLCOM_SHOW_ENGINE_STATUS]),
4518 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4519 {"show_events",
4520 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_EVENTS]),
4521 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4522 {"show_errors",
4523 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_ERRORS]),
4524 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4525 {"show_fields",
4526 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_FIELDS]),
4527 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4528 {"show_function_code",
4529 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_FUNC_CODE]),
4530 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4531 {"show_function_status",
4532 (char *)offsetof(System_status_var,
4533 com_stat[(uint)SQLCOM_SHOW_STATUS_FUNC]),
4534 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4535 {"show_grants",
4536 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_GRANTS]),
4537 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4538 {"show_index_statistics",
4539 (char *)offsetof(System_status_var,
4540 com_stat[(uint)SQLCOM_SHOW_INDEX_STATS]),
4541 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4542 {"show_keys",
4543 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_KEYS]),
4544 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4545 {"show_master_status",
4546 (char *)offsetof(System_status_var,
4547 com_stat[(uint)SQLCOM_SHOW_MASTER_STAT]),
4548 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4549 {"show_open_tables",
4550 (char *)offsetof(System_status_var,
4551 com_stat[(uint)SQLCOM_SHOW_OPEN_TABLES]),
4552 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4553 {"show_plugins",
4554 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PLUGINS]),
4555 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4556 {"show_privileges",
4557 (char *)offsetof(System_status_var,
4558 com_stat[(uint)SQLCOM_SHOW_PRIVILEGES]),
4559 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4560 {"show_procedure_code",
4561 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROC_CODE]),
4562 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4563 {"show_procedure_status",
4564 (char *)offsetof(System_status_var,
4565 com_stat[(uint)SQLCOM_SHOW_STATUS_PROC]),
4566 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4567 {"show_processlist",
4568 (char *)offsetof(System_status_var,
4569 com_stat[(uint)SQLCOM_SHOW_PROCESSLIST]),
4570 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4571 {"show_profile",
4572 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROFILE]),
4573 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4574 {"show_profiles",
4575 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROFILES]),
4576 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4577 {"show_relaylog_events",
4578 (char *)offsetof(System_status_var,
4579 com_stat[(uint)SQLCOM_SHOW_RELAYLOG_EVENTS]),
4580 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4581 {"show_replicas",
4582 (char *)offsetof(System_status_var,
4583 com_stat[(uint)SQLCOM_SHOW_SLAVE_HOSTS]),
4584 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4585 {"show_slave_hosts",
4586 (char *)offsetof(System_status_var,
4587 com_stat[(uint)SQLCOM_SHOW_SLAVE_HOSTS]),
4588 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4589 {"show_replica_status",
4590 (char *)offsetof(System_status_var,
4591 com_stat[(uint)SQLCOM_SHOW_SLAVE_STAT]),
4592 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4593 {"show_slave_status",
4594 (char *)offsetof(System_status_var,
4595 com_stat[(uint)SQLCOM_SHOW_SLAVE_STAT]),
4596 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4597 {"show_status",
4598 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_STATUS]),
4599 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4600 {"show_storage_engines",
4601 (char *)offsetof(System_status_var,
4602 com_stat[(uint)SQLCOM_SHOW_STORAGE_ENGINES]),
4603 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4604 {"show_table_statistics",
4605 (char *)offsetof(System_status_var,
4606 com_stat[(uint)SQLCOM_SHOW_TABLE_STATS]),
4607 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4608 {"show_table_status",
4609 (char *)offsetof(System_status_var,
4610 com_stat[(uint)SQLCOM_SHOW_TABLE_STATUS]),
4611 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4612 {"show_tables",
4613 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_TABLES]),
4614 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4615 {"show_thread_statistics",
4616 (char *)offsetof(System_status_var,
4617 com_stat[(uint)SQLCOM_SHOW_THREAD_STATS]),
4618 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4619 {"show_triggers",
4620 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_TRIGGERS]),
4621 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4622 {"show_user_statistics",
4623 (char *)offsetof(System_status_var,
4624 com_stat[(uint)SQLCOM_SHOW_USER_STATS]),
4625 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4626 {"show_variables",
4627 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_VARIABLES]),
4628 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4629 {"show_warnings",
4630 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_WARNS]),
4631 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4632 {"show_create_user",
4633 (char *)offsetof(System_status_var,
4634 com_stat[(uint)SQLCOM_SHOW_CREATE_USER]),
4635 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4636 {"shutdown",
4637 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHUTDOWN]),
4638 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4639 {"replica_start",
4640 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_START]),
4641 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4642 {"slave_start",
4643 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_START]),
4644 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4645 {"replica_stop",
4646 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_STOP]),
4647 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4648 {"slave_stop",
4649 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_STOP]),
4650 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4651 {"group_replication_start",
4652 (char *)offsetof(System_status_var,
4653 com_stat[(uint)SQLCOM_START_GROUP_REPLICATION]),
4654 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4655 {"group_replication_stop",
4656 (char *)offsetof(System_status_var,
4657 com_stat[(uint)SQLCOM_STOP_GROUP_REPLICATION]),
4658 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4659 {"stmt_execute", (char *)offsetof(System_status_var, com_stmt_execute),
4660 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4661 {"stmt_close", (char *)offsetof(System_status_var, com_stmt_close),
4662 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4663 {"stmt_fetch", (char *)offsetof(System_status_var, com_stmt_fetch),
4664 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4665 {"stmt_prepare", (char *)offsetof(System_status_var, com_stmt_prepare),
4666 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4667 {"stmt_reset", (char *)offsetof(System_status_var, com_stmt_reset),
4668 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4669 {"stmt_send_long_data",
4670 (char *)offsetof(System_status_var, com_stmt_send_long_data),
4671 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4672 {"truncate",
4673 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_TRUNCATE]),
4674 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4675 {"uninstall_component",
4676 (char *)offsetof(System_status_var,
4677 com_stat[(uint)SQLCOM_UNINSTALL_COMPONENT]),
4678 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4679 {"uninstall_plugin",
4680 (char *)offsetof(System_status_var,
4681 com_stat[(uint)SQLCOM_UNINSTALL_PLUGIN]),
4682 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4683 {"unlock_instance",
4684 (char *)offsetof(System_status_var,
4685 com_stat[(uint)SQLCOM_UNLOCK_INSTANCE]),
4686 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4687 {"unlock_tables",
4688 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UNLOCK_TABLES]),
4689 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4690 {"update",
4691 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UPDATE]),
4692 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4693 {"update_multi",
4694 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UPDATE_MULTI]),
4695 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4696 {"xa_commit",
4697 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_COMMIT]),
4698 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4699 {"xa_end",
4700 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_END]),
4701 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4702 {"xa_prepare",
4703 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_PREPARE]),
4704 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4705 {"xa_recover",
4706 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_RECOVER]),
4707 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4708 {"xa_rollback",
4709 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_ROLLBACK]),
4710 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4711 {"xa_start",
4712 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_START]),
4713 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4714 {NullS, NullS, SHOW_LONG, SHOW_SCOPE_ALL}};
4715
4716 LEX_CSTRING sql_statement_names[(uint)SQLCOM_END + 1];
4717
4718 12109 static void init_sql_statement_names() {
4719 12109 char *first_com = (char *)offsetof(System_status_var, com_stat[0]);
4720 12109 char *last_com =
4721 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_END]);
4722 12109 int record_size = (char *)offsetof(System_status_var, com_stat[1]) -
4723 (char *)offsetof(System_status_var, com_stat[0]);
4724 char *ptr;
4725 uint i;
4726 uint com_index;
4727
4728
2/2
✓ Branch 0 taken 2034312 times.
✓ Branch 1 taken 12109 times.
2046421 for (i = 0; i < ((uint)SQLCOM_END + 1); i++)
4729 2034312 sql_statement_names[i] = {STRING_WITH_LEN("")};
4730
4731 12109 SHOW_VAR *var = &com_status_vars[0];
4732
2/2
✓ Branch 0 taken 2167511 times.
✓ Branch 1 taken 12109 times.
2179620 while (var->name != nullptr) {
4733 2167511 ptr = var->value;
4734
3/4
✓ Branch 0 taken 2082748 times.
✓ Branch 1 taken 84763 times.
✓ Branch 2 taken 2082748 times.
✗ Branch 3 not taken.
2167511 if ((first_com <= ptr) && (ptr <= last_com)) {
4735 2082748 com_index = ((int)(ptr - first_com)) / record_size;
4736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082748 times.
2082748 assert(com_index < (uint)SQLCOM_END);
4737 2082748 sql_statement_names[com_index].str = var->name;
4738 /* TODO: Change SHOW_VAR::name to a LEX_STRING, to avoid strlen() */
4739 2082748 sql_statement_names[com_index].length = strlen(var->name);
4740 }
4741 2167511 var++;
4742 }
4743
4744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 assert(strcmp(sql_statement_names[(uint)SQLCOM_SELECT].str, "select") == 0);
4745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 assert(strcmp(sql_statement_names[(uint)SQLCOM_SIGNAL].str, "signal") == 0);
4746
4747 12109 sql_statement_names[(uint)SQLCOM_END].str = "error";
4748 12109 }
4749
4750 #ifdef HAVE_PSI_STATEMENT_INTERFACE
4751 PSI_statement_info sql_statement_info[(uint)SQLCOM_END + 1];
4752 PSI_statement_info com_statement_info[(uint)COM_END + 1];
4753
4754 /**
4755 Initialize the command names array.
4756 Since we do not want to maintain a separate array,
4757 this is populated from data mined in com_status_vars,
4758 which already has one name for each command.
4759 */
4760 12109 static void init_sql_statement_info() {
4761 uint i;
4762
4763
2/2
✓ Branch 0 taken 2034312 times.
✓ Branch 1 taken 12109 times.
2046421 for (i = 0; i < ((uint)SQLCOM_END + 1); i++) {
4764 2034312 sql_statement_info[i].m_name = sql_statement_names[i].str;
4765 2034312 sql_statement_info[i].m_flags = 0;
4766 2034312 sql_statement_info[i].m_documentation = PSI_DOCUMENT_ME;
4767 }
4768
4769 /* "statement/sql/error" represents broken queries (syntax error). */
4770 12109 sql_statement_info[(uint)SQLCOM_END].m_name = "error";
4771 12109 sql_statement_info[(uint)SQLCOM_END].m_flags = 0;
4772 12109 sql_statement_info[(uint)SQLCOM_END].m_documentation =
4773 "Invalid SQL queries (syntax error).";
4774
4775 /* "statement/sql/clone" will mutate to clone plugin statement */
4776 12109 sql_statement_info[(uint)SQLCOM_CLONE].m_flags = PSI_FLAG_MUTABLE;
4777 12109 }
4778
4779 12109 static void init_com_statement_info() {
4780 uint index;
4781
4782
2/2
✓ Branch 0 taken 423815 times.
✓ Branch 1 taken 12109 times.
435924 for (index = 0; index < (uint)COM_END + 1; index++) {
4783 423815 com_statement_info[index].m_name =
4784 423815 Command_names::str_notranslate(index).c_str();
4785 423815 com_statement_info[index].m_flags = 0;
4786 423815 com_statement_info[index].m_documentation = PSI_DOCUMENT_ME;
4787 }
4788
4789 /* "statement/abstract/query" can mutate into "statement/sql/..." */
4790 12109 com_statement_info[(uint)COM_QUERY].m_flags = PSI_FLAG_MUTABLE;
4791 12109 com_statement_info[(uint)COM_QUERY].m_documentation =
4792 "SQL query just received from the network. "
4793 "At this point, the real statement type is unknown, "
4794 "the type will be refined after SQL parsing.";
4795
4796 /* "statement/com/clone" will mutate to clone plugin statement */
4797 12109 com_statement_info[(uint)COM_CLONE].m_flags = PSI_FLAG_MUTABLE;
4798 12109 }
4799 #endif
4800
4801 /**
4802 Parse @@authentication_policy variable value.
4803
4804 @param [in] val Buffer holding variable value.
4805 @param [out] policy_list Vector holding the parsed values.
4806
4807 @retval false OK
4808 @retval true Error
4809 */
4810 23388 bool parse_authentication_policy(char *val,
4811 std::vector<std::string> &policy_list) {
4812 23388 std::string token;
4813
1/2
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
23388 std::string policy_val(val);
4814
2/4
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23388 times.
✗ Branch 3 not taken.
46776 std::stringstream policy_str(val);
4815 23388 bool is_empty = false;
4816 /* count comma */
4817
1/2
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
23388 size_t comma_cnt = std::count(policy_val.begin(), policy_val.end(), ',');
4818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23388 times.
23388 if (comma_cnt >= MAX_AUTH_FACTORS) return true;
4819 /*
4820 While parsing ensure that an empty value which means an optional nth factor,
4821 should be followed with an empty value only.
4822 Below are some invalid values:
4823 'caching_sha2_password,,authentication_fido'
4824 ',authentication_fido,authentication_ldap_simple'
4825 ',authentication_fido,'
4826 ',,'
4827 */
4828
4/6
✓ Branch 0 taken 70164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46776 times.
✓ Branch 5 taken 23388 times.
70164 while (getline(policy_str, token, ',')) {
4829
1/2
✓ Branch 0 taken 46776 times.
✗ Branch 1 not taken.
46776 std::string s(token);
4830 /* trim spaces */
4831
2/4
✓ Branch 0 taken 46776 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46776 times.
✗ Branch 3 not taken.
46776 s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
4832
4/6
✓ Branch 0 taken 23388 times.
✓ Branch 1 taken 23388 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23388 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 46776 times.
46776 if (s.length() && is_empty) {
4833 policy_list.clear();
4834 return true;
4835 };
4836
2/2
✓ Branch 0 taken 23388 times.
✓ Branch 1 taken 23388 times.
46776 if (!s.length()) is_empty = true;
4837
1/2
✓ Branch 0 taken 46776 times.
✗ Branch 1 not taken.
46776 policy_list.push_back(s);
4838
1/2
✓ Branch 0 taken 46776 times.
✗ Branch 1 not taken.
46776 }
4839 /*
4840 Values like 'caching_sha2_password,authentication_fido,' or
4841 'caching_sha2_password,,' will not capture the last empty value, thus append
4842 an empty value to the list.
4843 */
4844
3/6
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23388 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23388 times.
✗ Branch 5 not taken.
46776 if ((comma_cnt == policy_list.size()) &&
4845 23388 policy_list.size() < MAX_AUTH_FACTORS)
4846
2/4
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23388 times.
✗ Branch 3 not taken.
23388 policy_list.push_back("");
4847
4848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23388 times.
23388 if (policy_list.size() > MAX_AUTH_FACTORS) {
4849 policy_list.clear();
4850 return true;
4851 }
4852 23388 return false;
4853 23388 }
4854
4855 /**
4856 Validate @@authentication_policy variable value.
4857
4858 @param [in] val Buffer holding variable value.
4859
4860 @retval false success
4861 @retval true failure
4862 */
4863 11694 bool validate_authentication_policy(char *val) {
4864 11694 std::vector<std::string> list;
4865
2/4
✓ Branch 0 taken 11694 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11694 times.
11694 if (parse_authentication_policy(val, list)) return true;
4866
2/2
✓ Branch 0 taken 35082 times.
✓ Branch 1 taken 11694 times.
46776 for (auto it = list.begin(); it != list.end(); it++) {
4867 /* plugin name in first place holder cannot be empty */
4868
2/2
✓ Branch 0 taken 23388 times.
✓ Branch 1 taken 11694 times.
35082 if (!it->length()) {
4869
3/6
✓ Branch 0 taken 23388 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23388 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 23388 times.
23388 if (list.size() == 1 || it == list.begin()) return true;
4870 }
4871 /* skip special characters like * and <empty> string */
4872
2/2
✓ Branch 0 taken 23388 times.
✓ Branch 1 taken 11694 times.
46776 if (!it->length()) continue;
4873
1/2
✓ Branch 0 taken 11694 times.
✗ Branch 1 not taken.
11694 if (!it->compare("*")) continue;
4874 /* validate plugin name */
4875 plugin_ref p = my_plugin_lock_by_name(nullptr, to_lex_cstring(it->c_str()),
4876 MYSQL_AUTHENTICATION_PLUGIN);
4877 if (!p) goto error;
4878 st_mysql_auth *auth = (st_mysql_auth *)plugin_decl(p)->info;
4879 /*
4880 ensure 2nd and 3rd factor auth plugins which store password in mysql
4881 server are not allowed.
4882 */
4883 if (it != list.begin() &&
4884 auth->authentication_flags & AUTH_FLAG_USES_INTERNAL_STORAGE) {
4885 authentication_policy_plugin_ref.push_back(p);
4886 goto error;
4887 }
4888 /*
4889 ensure plugin name in first place holder cannot be auth plugin
4890 which requires registration step.
4891 */
4892 if (it == list.begin() &&
4893 auth->authentication_flags & AUTH_FLAG_REQUIRES_REGISTRATION) {
4894 authentication_policy_plugin_ref.push_back(p);
4895 goto error;
4896 }
4897 authentication_policy_plugin_ref.push_back(p);
4898 }
4899 11694 return false;
4900 error:
4901 for (auto p : authentication_policy_plugin_ref) plugin_unlock(nullptr, p);
4902 authentication_policy_plugin_ref.clear();
4903 return true;
4904 11694 }
4905
4906 /**
4907 Update @@authentication_policy variable value.
4908
4909 @retval false success
4910 @retval true failure
4911 */
4912 11694 bool update_authentication_policy() {
4913 11694 std::vector<std::string> list;
4914
2/4
✓ Branch 0 taken 11694 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11694 times.
11694 if (parse_authentication_policy(opt_authentication_policy, list)) return true;
4915 /* update the actual policy list only after validation is successful */
4916
1/2
✓ Branch 0 taken 11694 times.
✗ Branch 1 not taken.
11694 authentication_policy_list = list;
4917 /* release plugin reference */
4918
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11694 times.
11694 for (auto p : authentication_policy_plugin_ref) plugin_unlock(nullptr, p);
4919 11694 authentication_policy_plugin_ref.clear();
4920 11694 return false;
4921 11694 }
4922 /**
4923 Create a replication file name or base for file names.
4924
4925 @param key Instrumentation key used to track allocations
4926 @param[in] opt Value of option, or NULL
4927 @param[in] def Default value if option value is not set.
4928 @param[in] ext Extension to use for the path
4929
4930 @returns Pointer to string containing the full file path, or NULL if
4931 it was not possible to create the path.
4932 */
4933 47004 static inline const char *rpl_make_log_name(PSI_memory_key key, const char *opt,
4934 const char *def, const char *ext) {
4935
1/2
✓ Branch 0 taken 47004 times.
✗ Branch 1 not taken.
47004 DBUG_TRACE;
4936
3/12
✓ Branch 0 taken 47004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47004 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 47004 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
47004 DBUG_PRINT("enter", ("opt: %s, def: %s, ext: %s", (opt && opt[0]) ? opt : "",
4937 def, ext));
4938 char buff[FN_REFLEN];
4939 /*
4940 opt[0] needs to be checked to make sure opt name is not an empty
4941 string, in case it is an empty string default name will be considered
4942 */
4943
3/4
✓ Branch 0 taken 14641 times.
✓ Branch 1 taken 32363 times.
✓ Branch 2 taken 14641 times.
✗ Branch 3 not taken.
47004 const char *base = (opt && opt[0]) ? opt : def;
4944 47004 unsigned int options = MY_REPLACE_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH;
4945
4946 /* mysql_real_data_home_ptr may be null if no value of datadir has been
4947 specified through command-line or througha cnf file. If that is the
4948 case we make mysql_real_data_home_ptr point to mysql_real_data_home
4949 which, in that case holds the default path for data-dir.
4950 */
4951
4952
3/4
✓ Branch 0 taken 47004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 47000 times.
47004 DBUG_EXECUTE_IF("emulate_empty_datadir_param",
4953 { mysql_real_data_home_ptr = nullptr; };);
4954
4955
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 47000 times.
47004 if (mysql_real_data_home_ptr == nullptr)
4956 4 mysql_real_data_home_ptr = mysql_real_data_home;
4957
4958
2/4
✓ Branch 0 taken 47004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47004 times.
✗ Branch 3 not taken.
47004 if (fn_format(buff, base, mysql_real_data_home_ptr, ext, options))
4959
1/2
✓ Branch 0 taken 47004 times.
✗ Branch 1 not taken.
47004 return my_strdup(key, buff, MYF(0));
4960 else
4961 return nullptr;
4962 47004 }
4963
4964 12142 int init_common_variables() {
4965 12142 my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
4966 12142 tzset(); // Set tzname
4967
4968 12142 max_system_variables.pseudo_thread_id = (my_thread_id)~0;
4969 12142 server_start_time = flush_status_time = time(nullptr);
4970
4971
1/2
✓ Branch 0 taken 12142 times.
✗ Branch 1 not taken.
12142 binlog_filter = new Rpl_filter;
4972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12142 times.
12142 if (!binlog_filter) {
4973 LogErr(ERROR_LEVEL, ER_RPL_BINLOG_FILTERS_OOM, strerror(errno));
4974 return 1;
4975 }
4976
4977
3/6
✓ Branch 0 taken 12142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12142 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12142 times.
12142 if (init_thread_environment() || mysql_init_variables()) return 1;
4978
4979 {
4980 #ifdef _WIN32
4981 strmake(system_time_zone_dst_off, _tzname[0],
4982 sizeof(system_time_zone_dst_off) - 1);
4983 strmake(system_time_zone_dst_on, _tzname[1],
4984 sizeof(system_time_zone_dst_on) - 1);
4985 #else
4986 12142 strmake(system_time_zone_dst_off, tzname[0],
4987 sizeof(system_time_zone_dst_off) - 1);
4988 12142 strmake(system_time_zone_dst_on, tzname[1],
4989 sizeof(system_time_zone_dst_on) - 1);
4990 #endif
4991 }
4992 /*
4993 We set SYSTEM time zone as reasonable default and
4994 also for failure of my_tz_init() and bootstrap mode.
4995 If user explicitly set time zone with --default-time-zone
4996 option we will change this value in my_tz_init().
4997 */
4998 12142 global_system_variables.time_zone = my_tz_SYSTEM;
4999
5000 #ifdef HAVE_PSI_INTERFACE
5001 /*
5002 Complete the mysql_bin_log initialization.
5003 Instrumentation keys are known only after the performance schema
5004 initialization, and can not be set in the MYSQL_BIN_LOG constructor (called
5005 before main()).
5006 */
5007 12142 mysql_bin_log.set_psi_keys(
5008 key_BINLOG_LOCK_index, key_BINLOG_LOCK_commit,
5009 key_BINLOG_LOCK_commit_queue, key_BINLOG_LOCK_done,
5010 key_BINLOG_LOCK_flush_queue, key_BINLOG_LOCK_log,
5011 key_BINLOG_LOCK_binlog_end_pos, key_BINLOG_LOCK_sync,
5012 key_BINLOG_LOCK_sync_queue, key_BINLOG_LOCK_xids, key_BINLOG_COND_done,
5013 key_BINLOG_COND_flush_queue, key_BINLOG_update_cond,
5014 key_BINLOG_prep_xids_cond, key_file_binlog, key_file_binlog_index,
5015 key_file_binlog_cache, key_file_binlog_index_cache);
5016 #endif
5017
5018 /*
5019 Init mutexes for the global MYSQL_BIN_LOG objects.
5020 As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of
5021 global MYSQL_BIN_LOGs in their constructors, because then they would be
5022 inited before MY_INIT(). So we do it here.
5023 */
5024 12142 mysql_bin_log.init_pthread_objects();
5025
5026 /* TODO: remove this when my_time_t is 64 bit compatible */
5027
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12142 times.
12142 if (!is_time_t_valid_for_timestamp(server_start_time)) {
5028 LogErr(ERROR_LEVEL, ER_UNSUPPORTED_DATE);
5029 return 1;
5030 }
5031
5032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12142 times.
12142 if (gethostname(glob_hostname, sizeof(glob_hostname)) < 0) {
5033 strmake(glob_hostname, STRING_WITH_LEN("localhost"));
5034 LogErr(WARNING_LEVEL, ER_CALL_ME_LOCALHOST, glob_hostname);
5035 strmake(default_logfile_name, STRING_WITH_LEN("mysql"));
5036 } else
5037 12142 strmake(default_logfile_name, glob_hostname,
5038 sizeof(default_logfile_name) - 5);
5039
5040 12142 strmake(default_binlogfile_name, STRING_WITH_LEN("binlog"));
5041
3/4
✓ Branch 0 taken 11841 times.
✓ Branch 1 taken 301 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11841 times.
12142 if (opt_initialize || opt_initialize_insecure) {
5042 /*
5043 System tables initialization are not binary logged (regardless
5044 --log-bin option).
5045
5046 Disable binary log while executing any user script sourced while
5047 initializing system except if explicitly requested.
5048 */
5049 301 opt_bin_log = false;
5050 }
5051
5052 12142 strmake(pidfile_name, default_logfile_name, sizeof(pidfile_name) - 5);
5053 12142 my_stpcpy(fn_ext(pidfile_name), ".pid"); // Add proper extension
5054
5055 /*
5056 The default-storage-engine entry in my_long_options should have a
5057 non-null default value. It was earlier initialized as
5058 (longlong)"MyISAM" in my_long_options but this triggered a
5059 compiler error in the Sun Studio 12 compiler. As a work-around we
5060 set the def_value member to 0 in my_long_options and initialize it
5061 to the correct value here.
5062
5063 From MySQL 5.5 onwards, the default storage engine is InnoDB.
5064 */
5065 12142 default_storage_engine = "InnoDB";
5066 12142 default_tmp_storage_engine = default_storage_engine;
5067
5068 /*
5069 Add server status variables to the dynamic list of
5070 status variables that is shown by SHOW STATUS.
5071 Later, in plugin_register_builtin_and_init_core_se(),
5072 plugin_register_dynamic_and_init_all() and
5073 mysql_install_plugin(), new entries could be added
5074 to that list.
5075 */
5076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12142 times.
12142 if (add_status_vars(status_vars)) return 1; // an error was already reported
5077
5078 #ifndef NDEBUG
5079 /*
5080 We have few debug-only commands in com_status_vars, only visible in debug
5081 builds. for simplicity we enable the assert only in debug builds
5082
5083 There are 8 Com_ variables which don't have corresponding SQLCOM_ values:
5084 (TODO strictly speaking they shouldn't be here, should not have Com_ prefix
5085 that is. Perhaps Stmt_ ? Comstmt_ ? Prepstmt_ ?)
5086
5087 Com_admin_commands => com_other
5088 Com_stmt_close => com_stmt_close
5089 Com_stmt_execute => com_stmt_execute
5090 Com_stmt_fetch => com_stmt_fetch
5091 Com_stmt_prepare => com_stmt_prepare
5092 Com_stmt_reprepare => com_stmt_reprepare
5093 Com_stmt_reset => com_stmt_reset
5094 Com_stmt_send_long_data => com_stmt_send_long_data
5095
5096 We also have aliases for 5 com_status_vars:
5097
5098 Com_slave_start => Com_replica_start
5099 Com_slave_stop => Com_replica_stop
5100 Com_show_slave_status => Com_show_replica_status
5101 Com_show_slave_hosts => Com_show_replicas
5102 Com_change_master => Com_change_replication_source
5103
5104 With this correction the number of Com_ variables (number of elements in
5105 the array, excluding the last element - terminator) must match the number
5106 of SQLCOM_ constants.
5107 */
5108 static_assert(sizeof(com_status_vars) / sizeof(com_status_vars[0]) - 1 ==
5109 SQLCOM_END + 12,
5110 "");
5111 #endif
5112
5113
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 12108 times.
12142 if (get_options(&remaining_argc, &remaining_argv)) return 1;
5114
5115 /*
5116 The opt_bin_log can be false (binary log is disabled) only if
5117 --skip-log-bin/--disable-log-bin is configured or while the
5118 system is initializing.
5119 */
5120
2/2
✓ Branch 0 taken 614 times.
✓ Branch 1 taken 11494 times.
12108 if (!opt_bin_log) {
5121 /*
5122 The log-replica-updates should be disabled if binary log is disabled
5123 and --log-replica-updates option is not set explicitly on command
5124 line or configuration file.
5125 */
5126
2/2
✓ Branch 0 taken 425 times.
✓ Branch 1 taken 189 times.
614 if (!log_replica_updates_supplied) opt_log_replica_updates = false;
5127 }
5128
5129
1/2
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
12108 if (opt_protocol_compression_algorithms) {
5130
1/2
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
24216 if ((opt_protocol_compression_algorithms[0] == 0) ||
5131
3/4
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 12107 times.
12108 (validate_compression_attributes(
5132
6/16
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12108 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 12107 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
24216 std::string(opt_protocol_compression_algorithms), std::string(),
5133 true))) {
5134 /*
5135 --protocol-compression-algorithms is set to invalid value, resetting
5136 its value to default "zlib,zstd,uncompressed"
5137 */
5138 1 opt_protocol_compression_algorithms =
5139 const_cast<char *>(PROTOCOL_COMPRESSION_DEFAULT_VALUE);
5140
7/14
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
1 LogErr(WARNING_LEVEL, ER_PROTOCOL_COMPRESSION_RESET_LOG);
5141 }
5142 }
5143 12108 update_parser_max_mem_size();
5144
5145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (set_default_auth_plugin(default_auth_plugin,
5146 strlen(default_auth_plugin))) {
5147 LogErr(ERROR_LEVEL, ER_AUTH_CANT_SET_DEFAULT_PLUGIN);
5148 return 1;
5149 }
5150 12108 set_server_version();
5151
5152
2/2
✓ Branch 0 taken 12090 times.
✓ Branch 1 taken 18 times.
12108 if (!is_help_or_validate_option()) {
5153
7/14
✓ Branch 0 taken 12090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12090 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12090 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12090 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12090 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12090 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12090 times.
✗ Branch 13 not taken.
12090 LogErr(INFORMATION_LEVEL, ER_BASEDIR_SET_TO, mysql_home);
5154 }
5155
5/6
✓ Branch 0 taken 12103 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 11802 times.
✓ Branch 3 taken 301 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 11802 times.
12108 if (!opt_validate_config && (opt_initialize || opt_initialize_insecure)) {
5156
7/14
✓ Branch 0 taken 301 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 301 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 301 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 301 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 301 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 301 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 301 times.
✗ Branch 13 not taken.
301 LogErr(SYSTEM_LEVEL, ER_STARTING_INIT, my_progname, server_version,
5157 (ulong)getpid());
5158
2/2
✓ Branch 0 taken 11790 times.
✓ Branch 1 taken 17 times.
11807 } else if (!is_help_or_validate_option()) {
5159
7/14
✓ Branch 0 taken 11790 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11790 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11790 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11790 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11790 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11790 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11790 times.
✗ Branch 13 not taken.
11790 LogErr(SYSTEM_LEVEL, ER_STARTING_AS, my_progname, server_version,
5160 (ulong)getpid());
5161 }
5162
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 12095 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
12108 if (opt_help && !opt_verbose) unireg_abort(MYSQLD_SUCCESS_EXIT);
5163
5164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 DBUG_PRINT("info", ("%s Ver %s for %s on %s\n", my_progname, server_version,
5165 SYSTEM_TYPE, MACHINE_TYPE));
5166
5167 #ifdef HAVE_LINUX_LARGE_PAGES
5168 /* Initialize large page size */
5169
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12108 times.
12108 if (opt_large_pages && (opt_large_page_size = my_get_large_page_size())) {
5170 DBUG_PRINT("info",
5171 ("Large page set, large_page_size = %d", opt_large_page_size));
5172 } else {
5173 12108 opt_large_pages = false;
5174 /*
5175 Either not configured to use large pages or Linux haven't
5176 been compiled with large page support
5177 */
5178 }
5179 #endif /* HAVE_LINUX_LARGE_PAGES */
5180 #ifdef HAVE_SOLARIS_LARGE_PAGES
5181 #define LARGE_PAGESIZE (4 * 1024 * 1024) /* 4MB */
5182 #define SUPER_LARGE_PAGESIZE (256 * 1024 * 1024) /* 256MB */
5183 if (opt_large_pages) {
5184 /*
5185 tell the kernel that we want to use 4/256MB page for heap storage
5186 and also for the stack. We use 4 MByte as default and if the
5187 super-large-page is set we increase it to 256 MByte. 256 MByte
5188 is for server installations with GBytes of RAM memory where
5189 the MySQL Server will have page caches and other memory regions
5190 measured in a number of GBytes.
5191 We use as big pages as possible which isn't bigger than the above
5192 desired page sizes.
5193 */
5194 int nelem;
5195 size_t max_desired_page_size;
5196 if (opt_super_large_pages)
5197 max_desired_page_size = SUPER_LARGE_PAGESIZE;
5198 else
5199 max_desired_page_size = LARGE_PAGESIZE;
5200 nelem = getpagesizes(NULL, 0);
5201 if (nelem > 0) {
5202 size_t *pagesize = (size_t *)malloc(sizeof(size_t) * nelem);
5203 if (pagesize != NULL && getpagesizes(pagesize, nelem) > 0) {
5204 size_t max_page_size = 0;
5205 for (int i = 0; i < nelem; i++) {
5206 if (pagesize[i] > max_page_size &&
5207 pagesize[i] <= max_desired_page_size)
5208 max_page_size = pagesize[i];
5209 }
5210 free(pagesize);
5211 if (max_page_size > 0) {
5212 struct memcntl_mha mpss;
5213
5214 mpss.mha_cmd = MHA_MAPSIZE_BSSBRK;
5215 mpss.mha_pagesize = max_page_size;
5216 mpss.mha_flags = 0;
5217 memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
5218 mpss.mha_cmd = MHA_MAPSIZE_STACK;
5219 memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
5220 }
5221 }
5222 }
5223 }
5224 #endif /* HAVE_SOLARIS_LARGE_PAGES */
5225
5226 longlong default_value;
5227 sys_var *var;
5228 /* Calculate and update default value for thread_cache_size. */
5229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if ((default_value = 8 + max_connections / 100) > 100) default_value = 100;
5230
2/4
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12108 times.
✗ Branch 3 not taken.
12108 var = find_static_system_variable("thread_cache_size");
5231 12108 var->update_default(default_value);
5232
5233 /* Calculate and update default value for host_cache_size. */
5234
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12107 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12108 times.
12109 if ((default_value = 128 + max_connections) > 628 &&
5235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 (default_value = 628 + ((max_connections - 500) / 20)) > 2000)
5236 default_value = 2000;
5237
2/4
✓ Branch 0 taken 12108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12108 times.
✗ Branch 3 not taken.
12108 var = find_static_system_variable("host_cache_size");
5238 12108 var->update_default(default_value);
5239
5240 /* Fix thread_cache_size. */
5241
3/4
✓ Branch 0 taken 12106 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12108 times.
24214 if (!thread_cache_size_specified &&
5242 12106 (Per_thread_connection_handler::max_blocked_pthreads =
5243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12106 times.
12106 8 + max_connections / 100) > 100)
5244 Per_thread_connection_handler::max_blocked_pthreads = 100;
5245
5246 /* Fix host_cache_size. */
5247 36322 if (!host_cache_size_specified &&
5248
5/6
✓ Branch 0 taken 12106 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 12105 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12108 times.
12109 (host_cache_size = 128 + max_connections) > 628 &&
5249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 (host_cache_size = 628 + ((max_connections - 500) / 20)) > 2000)
5250 host_cache_size = 2000;
5251
5252 /* Fix back_log */
5253
4/6
✓ Branch 0 taken 12105 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12105 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12108 times.
12108 if (back_log == 0 && (back_log = max_connections) > 65535) back_log = 65535;
5254
5255 12108 unireg_init(opt_specialflag); /* Set up extern variables */
5256 12108 while (!(my_default_lc_messages =
5257
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12108 times.
12110 my_locale_by_name(nullptr, lc_messages, strlen(lc_messages)))) {
5258
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_LOCALE_NAME, lc_messages);
5259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!my_strcasecmp(&my_charset_latin1, lc_messages,
5260 mysqld_default_locale_name))
5261 return 1;
5262 2 lc_messages = mysqld_default_locale_name;
5263 }
5264 12108 global_system_variables.lc_messages = my_default_lc_messages;
5265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (init_errmessage()) /* Read error messages from file */
5266 return 1;
5267 12108 init_client_errs();
5268
5269 12108 mysql_client_plugin_init();
5270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (item_create_init()) return 1;
5271 12108 item_init();
5272 12108 range_optimizer_init();
5273 12108 my_string_stack_guard = check_enough_stack_size;
5274 /*
5275 Process a comma-separated character set list and choose
5276 the first available character set. This is mostly for
5277 test purposes, to be able to start "mysqld" even if
5278 the requested character set is not available (see bug#18743).
5279 */
5280 for (;;) {
5281 char *next_character_set_name =
5282 12108 strchr(const_cast<char *>(default_character_set_name), ',');
5283
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12106 times.
12108 if (next_character_set_name) *next_character_set_name++ = '\0';
5284
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12107 times.
12108 if (!(default_charset_info = get_charset_by_csname(
5285 default_character_set_name, MY_CS_PRIMARY, MYF(MY_WME)))) {
5286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (next_character_set_name) {
5287 default_character_set_name = next_character_set_name;
5288 default_collation_name = nullptr; // Ignore collation
5289 } else
5290 1 return 1; // Eof of the list
5291 } else {
5292 12107 warn_on_deprecated_charset(nullptr, default_charset_info,
5293 default_character_set_name,
5294 "--character-set-server");
5295 12107 break;
5296 }
5297 }
5298
5299
2/2
✓ Branch 0 taken 12088 times.
✓ Branch 1 taken 19 times.
12107 if (default_collation_name) {
5300 CHARSET_INFO *default_collation;
5301 12088 default_collation = get_charset_by_name(default_collation_name, MYF(0));
5302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12088 times.
12088 if (!default_collation) {
5303 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_COLLATION_NAME,
5304 default_collation_name);
5305 return 1;
5306 }
5307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12088 times.
12088 if (!my_charset_same(default_charset_info, default_collation)) {
5308 LogErr(ERROR_LEVEL, ER_INVALID_COLLATION_FOR_CHARSET,
5309 default_collation_name, default_charset_info->csname);
5310 return 1;
5311 }
5312 12088 warn_on_deprecated_collation(nullptr, default_collation,
5313 "--collation-server");
5314 12088 default_charset_info = default_collation;
5315 }
5316 /* Set collactions that depends on the default collation */
5317 12107 global_system_variables.collation_server = default_charset_info;
5318 12107 global_system_variables.collation_database = default_charset_info;
5319 12107 global_system_variables.default_collation_for_utf8mb4 =
5320 &my_charset_utf8mb4_0900_ai_ci;
5321
5322
2/2
✓ Branch 0 taken 12093 times.
✓ Branch 1 taken 14 times.
12107 if (is_supported_parser_charset(default_charset_info)) {
5323 12093 global_system_variables.collation_connection = default_charset_info;
5324 12093 global_system_variables.character_set_results = default_charset_info;
5325 12093 global_system_variables.character_set_client = default_charset_info;
5326 } else {
5327
7/14
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 14 times.
✗ Branch 13 not taken.
14 LogErr(INFORMATION_LEVEL, ER_FIXING_CLIENT_CHARSET,
5328 default_charset_info->csname, my_charset_latin1.csname);
5329 14 global_system_variables.collation_connection = &my_charset_latin1;
5330 14 global_system_variables.character_set_results = &my_charset_latin1;
5331 14 global_system_variables.character_set_client = &my_charset_latin1;
5332 }
5333
5334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12107 times.
12107 if (!(character_set_filesystem = get_charset_by_csname(
5335 character_set_filesystem_name, MY_CS_PRIMARY, MYF(MY_WME))))
5336 return 1;
5337 else
5338 12107 warn_on_deprecated_charset(nullptr, character_set_filesystem,
5339 character_set_filesystem_name,
5340 "--character-set-filesystem");
5341 12107 global_system_variables.character_set_filesystem = character_set_filesystem;
5342
5343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12107 times.
12107 if (lex_init()) {
5344 LogErr(ERROR_LEVEL, ER_OOM);
5345 return 1;
5346 }
5347
5348
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12107 times.
12109 while (!(my_default_lc_time_names = my_locale_by_name(
5349 nullptr, lc_time_names_name, strlen(lc_time_names_name)))) {
5350
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_LOCALE_NAME, lc_time_names_name);
5351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!my_strcasecmp(&my_charset_latin1, lc_time_names_name,
5352 mysqld_default_locale_name))
5353 return 1;
5354 2 lc_time_names_name = mysqld_default_locale_name;
5355 }
5356 12107 global_system_variables.lc_time_names = my_default_lc_time_names;
5357
5358 /* check log options and issue warnings if needed */
5359
3/4
✓ Branch 0 taken 11534 times.
✓ Branch 1 taken 573 times.
✓ Branch 2 taken 11534 times.
✗ Branch 3 not taken.
12107 if (opt_general_log && opt_general_logname &&
5360
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11534 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11534 !(log_output_options & LOG_FILE) && !(log_output_options & LOG_NONE))
5361 LogErr(WARNING_LEVEL, ER_LOG_FILES_GIVEN_LOG_OUTPUT_IS_TABLE,
5362 "--general-log-file option");
5363
5364
4/6
✓ Branch 0 taken 11534 times.
✓ Branch 1 taken 573 times.
✓ Branch 2 taken 11534 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11534 times.
12107 if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE) &&
5365 !(log_output_options & LOG_NONE))
5366 LogErr(WARNING_LEVEL, ER_LOG_FILES_GIVEN_LOG_OUTPUT_IS_TABLE,
5367 "--slow-query-log-file option");
5368
5369
3/4
✓ Branch 0 taken 11538 times.
✓ Branch 1 taken 569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12107 times.
23645 if (opt_general_logname &&
5370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11538 times.
11538 !is_valid_log_name(opt_general_logname, strlen(opt_general_logname))) {
5371 LogErr(ERROR_LEVEL, ER_LOG_FILE_INVALID, "--general_log_file",
5372 opt_general_logname);
5373 return 1;
5374 }
5375
5376
3/4
✓ Branch 0 taken 11538 times.
✓ Branch 1 taken 569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12107 times.
23645 if (opt_slow_logname &&
5377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11538 times.
11538 !is_valid_log_name(opt_slow_logname, strlen(opt_slow_logname))) {
5378 LogErr(ERROR_LEVEL, ER_LOG_FILE_INVALID, "--slow_query_log_file",
5379 opt_slow_logname);
5380 return 1;
5381 }
5382
5383
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12103 times.
12107 if (global_system_variables.transaction_write_set_extraction ==
5384 4 HASH_ALGORITHM_OFF &&
5385
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 mysql_bin_log.m_dependency_tracker.m_opt_tracking_mode !=
5386 DEPENDENCY_TRACKING_COMMIT_ORDER) {
5387
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL,
5388 ER_TX_EXTRACTION_ALGORITHM_FOR_BINLOG_TX_DEPEDENCY_TRACKING,
5389 "XXHASH64 or MURMUR32", "WRITESET or WRITESET_SESSION");
5390 2 return 1;
5391 } else
5392 12105 mysql_bin_log.m_dependency_tracker.tracking_mode_changed();
5393
5394 #define FIX_LOG_VAR(VAR, ALT) \
5395 if (!VAR || !*VAR) VAR = ALT;
5396
5397
3/4
✓ Branch 0 taken 11536 times.
✓ Branch 1 taken 569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11536 times.
12105 FIX_LOG_VAR(opt_general_logname,
5398 make_query_log_name(logname_path, QUERY_LOG_GENERAL));
5399
3/4
✓ Branch 0 taken 11536 times.
✓ Branch 1 taken 569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11536 times.
12105 FIX_LOG_VAR(opt_slow_logname,
5400 my_strdup(key_memory_LOG_name,
5401 make_query_log_name(slow_logname_path, QUERY_LOG_SLOW),
5402 MYF(MY_WME)));
5403
5404 #if defined(ENABLED_DEBUG_SYNC)
5405 /* Initialize the debug sync facility. See debug_sync.cc. */
5406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12105 times.
12105 if (debug_sync_init()) return 1; /* purecov: tested */
5407 #endif /* defined(ENABLED_DEBUG_SYNC) */
5408
5409
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12100 times.
12105 if (opt_validate_config) return 0;
5410
5411 /* create the data directory if requested */
5412
4/4
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 11799 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12097 times.
12401 if (unlikely(opt_initialize) &&
5413
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 298 times.
301 initialize_create_data_directory(mysql_real_data_home))
5414 3 return 1;
5415
5416 /*
5417 Ensure that lower_case_table_names is set on system where we have case
5418 insensitive names. If this is not done the users MyISAM tables will
5419 get corrupted if accesses with names of different case.
5420 */
5421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12097 times.
12097 DBUG_PRINT("info", ("lower_case_table_names: %d", lower_case_table_names));
5422 12097 lower_case_file_system =
5423 12097 (test_if_case_insensitive(mysql_real_data_home) == 1);
5424
3/4
✓ Branch 0 taken 11863 times.
✓ Branch 1 taken 234 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11863 times.
12097 if (!lower_case_table_names && lower_case_file_system) {
5425 if (lower_case_table_names_used) {
5426 LogErr(ERROR_LEVEL, ER_LOWER_CASE_TABLE_NAMES_CS_DD_ON_CI_FS_UNSUPPORTED);
5427 return 1;
5428 } else {
5429 LogErr(WARNING_LEVEL, ER_LOWER_CASE_TABLE_NAMES_USING_2,
5430 mysql_real_data_home);
5431 lower_case_table_names = 2;
5432 }
5433
3/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 12081 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
12097 } else if (lower_case_table_names == 2 && !lower_case_file_system) {
5434
7/14
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
16 LogErr(WARNING_LEVEL, ER_LOWER_CASE_TABLE_NAMES_USING_0,
5435 mysql_real_data_home);
5436 16 lower_case_table_names = 0;
5437 }
5438
5439 /* Reset table_alias_charset, now that lower_case_table_names is set. */
5440 12097 table_alias_charset =
5441
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 11879 times.
12097 (lower_case_table_names ? &my_charset_utf8_tolower_ci : &my_charset_bin);
5442
5443 /*
5444 Build do_table and ignore_table rules to hashes
5445 after the resetting of table_alias_charset.
5446 */
5447
2/4
✓ Branch 0 taken 12097 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12097 times.
24194 if (rpl_global_filter.build_do_table_hash() ||
5448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12097 times.
12097 rpl_global_filter.build_ignore_table_hash()) {
5449 LogErr(ERROR_LEVEL, ER_CANT_HASH_DO_AND_IGNORE_RULES);
5450 return 1;
5451 }
5452
5453 /*
5454 Reset the P_S view for global replication filter at
5455 the end of server startup.
5456 */
5457 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
5458 12097 rpl_global_filter.wrlock();
5459 12097 rpl_global_filter.reset_pfs_view();
5460 12097 rpl_global_filter.unlock();
5461 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
5462
5463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12097 times.
12097 if (rpl_channel_filters.build_do_and_ignore_table_hashes()) return 1;
5464
5465 12097 return 0;
5466 }
5467
5468 12142 static int init_thread_environment() {
5469 12142 mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
5470 12142 mysql_mutex_init(key_LOCK_manager, &LOCK_manager, MY_MUTEX_INIT_FAST);
5471 12142 mysql_mutex_init(key_LOCK_crypt, &LOCK_crypt, MY_MUTEX_INIT_FAST);
5472 12142 mysql_mutex_init(key_LOCK_user_conn, &LOCK_user_conn, MY_MUTEX_INIT_FAST);
5473 12142 mysql_mutex_init(key_LOCK_global_system_variables,
5474 &LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
5475 12142 mysql_rwlock_init(key_rwlock_LOCK_system_variables_hash,
5476 &LOCK_system_variables_hash);
5477 12142 mysql_mutex_init(key_LOCK_prepared_stmt_count, &LOCK_prepared_stmt_count,
5478 MY_MUTEX_INIT_FAST);
5479 12142 mysql_mutex_init(key_LOCK_replica_list, &LOCK_replica_list,
5480 MY_MUTEX_INIT_FAST);
5481 12142 mysql_mutex_init(key_LOCK_sql_replica_skip_counter,
5482 &LOCK_sql_replica_skip_counter, MY_MUTEX_INIT_FAST);
5483 12142 mysql_mutex_init(key_LOCK_replica_net_timeout, &LOCK_replica_net_timeout,
5484 MY_MUTEX_INIT_FAST);
5485 12142 mysql_mutex_init(key_LOCK_replica_trans_dep_tracker,
5486 &LOCK_replica_trans_dep_tracker, MY_MUTEX_INIT_FAST);
5487 12142 mysql_mutex_init(key_LOCK_error_messages, &LOCK_error_messages,
5488 MY_MUTEX_INIT_FAST);
5489 12142 mysql_mutex_init(key_LOCK_uuid_generator, &LOCK_uuid_generator,
5490 MY_MUTEX_INIT_FAST);
5491 12142 mysql_mutex_init(key_LOCK_sql_rand, &LOCK_sql_rand, MY_MUTEX_INIT_FAST);
5492 12142 mysql_mutex_init(key_LOCK_log_throttle_qni, &LOCK_log_throttle_qni,
5493 MY_MUTEX_INIT_FAST);
5494 12142 mysql_mutex_init(key_LOCK_default_password_lifetime,
5495 &LOCK_default_password_lifetime, MY_MUTEX_INIT_FAST);
5496 12142 mysql_mutex_init(key_LOCK_mandatory_roles, &LOCK_mandatory_roles,
5497 MY_MUTEX_INIT_FAST);
5498 12142 mysql_mutex_init(key_LOCK_password_history, &LOCK_password_history,
5499 MY_MUTEX_INIT_FAST);
5500 12142 mysql_mutex_init(key_LOCK_password_reuse_interval,
5501 &LOCK_password_reuse_interval, MY_MUTEX_INIT_FAST);
5502 12142 mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect);
5503 12142 mysql_rwlock_init(key_rwlock_LOCK_sys_init_replica, &LOCK_sys_init_replica);
5504 12142 mysql_cond_init(key_COND_manager, &COND_manager);
5505 12142 mysql_mutex_init(key_LOCK_server_started, &LOCK_server_started,
5506 MY_MUTEX_INIT_FAST);
5507 12142 mysql_cond_init(key_COND_server_started, &COND_server_started);
5508 12142 mysql_mutex_init(key_LOCK_reset_gtid_table, &LOCK_reset_gtid_table,
5509 MY_MUTEX_INIT_FAST);
5510 12142 mysql_mutex_init(key_LOCK_compress_gtid_table, &LOCK_compress_gtid_table,
5511 MY_MUTEX_INIT_FAST);
5512 12142 mysql_mutex_init(key_LOCK_collect_instance_log, &LOCK_collect_instance_log,
5513 MY_MUTEX_INIT_FAST);
5514 12142 mysql_cond_init(key_COND_compress_gtid_table, &COND_compress_gtid_table);
5515
5516 12142 mysql_mutex_init(key_LOCK_global_user_client_stats,
5517 &LOCK_global_user_client_stats, MY_MUTEX_INIT_FAST);
5518 12142 mysql_mutex_init(key_LOCK_global_table_stats, &LOCK_global_table_stats,
5519 MY_MUTEX_INIT_FAST);
5520 12142 mysql_mutex_init(key_LOCK_global_index_stats, &LOCK_global_index_stats,
5521 MY_MUTEX_INIT_FAST);
5522
5523 12142 Events::init_mutexes();
5524 #if defined(_WIN32)
5525 mysql_mutex_init(key_LOCK_handler_count, &LOCK_handler_count,
5526 MY_MUTEX_INIT_FAST);
5527 mysql_cond_init(key_COND_handler_count, &COND_handler_count);
5528 mysql_rwlock_init(key_rwlock_LOCK_named_pipe_full_access_group,
5529 &LOCK_named_pipe_full_access_group);
5530 #else
5531 12142 mysql_mutex_init(key_LOCK_socket_listener_active,
5532 &LOCK_socket_listener_active, MY_MUTEX_INIT_FAST);
5533 12142 mysql_cond_init(key_COND_socket_listener_active,
5534 &COND_socket_listener_active);
5535 12142 mysql_mutex_init(key_LOCK_start_signal_handler, &LOCK_start_signal_handler,
5536 MY_MUTEX_INIT_FAST);
5537 12142 mysql_cond_init(key_COND_start_signal_handler, &COND_start_signal_handler);
5538 #endif // _WIN32
5539 /* Parameter for threads created for connections */
5540 12142 (void)my_thread_attr_init(&connection_attrib);
5541 12142 my_thread_attr_setdetachstate(&connection_attrib, MY_THREAD_CREATE_DETACHED);
5542 #ifndef _WIN32
5543 12142 pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
5544 #endif
5545
5546 12142 mysql_mutex_init(key_LOCK_keyring_operations, &LOCK_keyring_operations,
5547 MY_MUTEX_INIT_FAST);
5548 12142 mysql_mutex_init(key_LOCK_tls_ctx_options, &LOCK_tls_ctx_options,
5549 MY_MUTEX_INIT_FAST);
5550 12142 mysql_mutex_init(key_LOCK_rotate_binlog_master_key,
5551 &LOCK_rotate_binlog_master_key, MY_MUTEX_INIT_FAST);
5552 12142 mysql_mutex_init(key_LOCK_admin_tls_ctx_options, &LOCK_admin_tls_ctx_options,
5553 MY_MUTEX_INIT_FAST);
5554 12142 mysql_mutex_init(key_LOCK_partial_revokes, &LOCK_partial_revokes,
5555 MY_MUTEX_INIT_FAST);
5556 12142 mysql_mutex_init(key_LOCK_authentication_policy, &LOCK_authentication_policy,
5557 MY_MUTEX_INIT_FAST);
5558 12142 mysql_mutex_init(key_LOCK_global_conn_mem_limit, &LOCK_global_conn_mem_limit,
5559 MY_MUTEX_INIT_FAST);
5560 12142 return 0;
5561 }
5562
5563 static PSI_memory_key key_memory_openssl = PSI_NOT_INSTRUMENTED;
5564
5565 #if OPENSSL_VERSION_NUMBER < 0x10100000L
5566 #define FILE_LINE_ARGS
5567 #else
5568 #define FILE_LINE_ARGS , const char *, int
5569 #endif
5570
5571 140924066 static void *my_openssl_malloc(size_t size FILE_LINE_ARGS) {
5572 140924066 return my_malloc(key_memory_openssl, size, MYF(MY_WME));
5573 }
5574 5052889 static void *my_openssl_realloc(void *ptr, size_t size FILE_LINE_ARGS) {
5575 5052889 return my_realloc(key_memory_openssl, ptr, size, MYF(MY_WME));
5576 }
5577 182860362 static void my_openssl_free(void *ptr FILE_LINE_ARGS) { return my_free(ptr); }
5578
5579 12109 static void init_ssl() {
5580 #if defined(HAVE_PSI_MEMORY_INTERFACE)
5581 static PSI_memory_info all_openssl_memory[] = {
5582 {&key_memory_openssl, "openssl_malloc", 0, 0,
5583 "All memory used by openSSL"}};
5584 12109 mysql_memory_register("mysqld_openssl", all_openssl_memory,
5585 (int)array_elements(all_openssl_memory));
5586 #endif /* defined(HAVE_PSI_MEMORY_INTERFACE) */
5587 12109 int ret = CRYPTO_set_mem_functions(my_openssl_malloc, my_openssl_realloc,
5588 my_openssl_free);
5589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 if (ret == 0)
5590 LogErr(WARNING_LEVEL, ER_SSL_MEMORY_INSTRUMENTATION_INIT_FAILED,
5591 "CRYPTO_set_mem_functions");
5592 12109 ssl_start();
5593 12109 }
5594
5595 11768 static int init_ssl_communication() {
5596 11768 char ssl_err_string[OPENSSL_ERROR_LENGTH] = {'\0'};
5597
3/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11767 times.
11768 if (set_fips_mode(opt_ssl_fips_mode, ssl_err_string)) {
5598
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_SSL_FIPS_MODE_ERROR, ssl_err_string);
5599 1 return 1;
5600 }
5601
4/6
✓ Branch 0 taken 11767 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11767 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 11761 times.
11767 if (TLS_channel::singleton_init(&mysql_main, mysql_main_channel, opt_use_ssl,
5602 &server_main_callback, opt_initialize))
5603 6 return 1;
5604
5605 /*
5606 The default value of --admin-ssl is ON. If it is set
5607 to off, we should treat it as an explicit attempt to
5608 set TLS off for admin channel and thereby not use
5609 main channel's TLS configuration.
5610 */
5611
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11758 times.
11761 if (!opt_use_admin_ssl) g_admin_ssl_configured = true;
5612
5613 11761 bool initialize_admin_tls =
5614
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 11437 times.
11471 (!opt_initialize && (my_admin_bind_addr_str != nullptr))
5615
2/2
✓ Branch 0 taken 11471 times.
✓ Branch 1 taken 290 times.
23232 ? opt_use_admin_ssl
5616
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
34 : false;
5617
5618 11761 Ssl_init_callback_server_admin server_admin_callback;
5619
3/6
✓ Branch 0 taken 11761 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11761 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11761 times.
11761 if (TLS_channel::singleton_init(&mysql_admin, mysql_admin_channel,
5620 initialize_admin_tls, &server_admin_callback,
5621 opt_initialize))
5622 return 1;
5623
5624
6/6
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 11729 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 11741 times.
11761 if (initialize_admin_tls && !g_admin_ssl_configured) {
5625
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 Lock_and_access_ssl_acceptor_context context(mysql_main);
5626
3/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 1 times.
20 if (context.have_ssl())
5627
8/16
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 19 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 19 times.
✗ Branch 15 not taken.
19 LogErr(SYSTEM_LEVEL, ER_TLS_CONFIGURATION_REUSED,
5628 mysql_admin_channel.c_str(), mysql_main_channel.c_str());
5629 20 }
5630
5631 #if OPENSSL_VERSION_NUMBER < 0x10100000L
5632 ERR_remove_thread_state(0);
5633 #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
5634
5635
3/4
✓ Branch 0 taken 11761 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 11758 times.
11761 if (init_rsa_keys()) return 1;
5636 11758 return 0;
5637 11761 }
5638
5639 10491 static void end_ssl() {
5640 10491 TLS_channel::singleton_deinit(mysql_main);
5641 10491 TLS_channel::singleton_deinit(mysql_admin);
5642 10491 deinit_rsa_keys();
5643 10491 }
5644
5645 /**
5646 Generate a UUID and save it into server_uuid variable.
5647
5648 @return Return 0 or 1 if an error occurred.
5649 */
5650 5311 static int generate_server_uuid() {
5651 THD *thd;
5652 Item_func_uuid *func_uuid;
5653 5311 String uuid;
5654
5655 /*
5656 To be able to run this from boot, we allocate a temporary THD,
5657 since plugins are not yet loaded we pass false to temporary THD.
5658 */
5659
3/6
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5311 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5311 times.
5311 if (!(thd = new THD(false))) {
5660 LogErr(ERROR_LEVEL, ER_NO_THD_NO_UUID);
5661 return 1;
5662 }
5663 5311 thd->thread_stack = (char *)&thd;
5664
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 thd->store_globals();
5665
5666 /*
5667 Initialize the variables which are used during "uuid generator
5668 initialization" with values that should normally differ between
5669 mysqlds on the same host. This avoids that another mysqld started
5670 at the same time on the same host get the same "server_uuid".
5671 */
5672
5673 5311 const time_t save_server_start_time = server_start_time;
5674 5311 server_start_time += ((ulonglong)current_pid << 48) + current_pid;
5675 5311 thd->status_var.bytes_sent = (ulonglong)thd;
5676
5677
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 lex_start(thd);
5678
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
10622 func_uuid = new (thd->mem_root) Item_func_uuid();
5679 5311 func_uuid->fixed = true;
5680
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 func_uuid->val_str(&uuid);
5681
5682 // Restore global variables used for salting
5683 5311 server_start_time = save_server_start_time;
5684
5685
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 delete thd;
5686
5687
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 strncpy(server_uuid, uuid.c_ptr(), sizeof(server_uuid));
5688
3/4
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 5308 times.
5311 DBUG_EXECUTE_IF("server_uuid_deterministic",
5689 memcpy(server_uuid, "00000000-1111-0000-1111-000000000000",
5690 UUID_LENGTH););
5691 5311 server_uuid[UUID_LENGTH] = '\0';
5692 5311 return 0;
5693 5311 }
5694
5695 /**
5696 Save all options which was auto-generated by server-self into the given file.
5697
5698 @param fname The name of the file in which the auto-generated options will b
5699 e saved.
5700
5701 @return Return 0 or 1 if an error occurred.
5702 */
5703 5311 static int flush_auto_options(const char *fname) {
5704 File fd;
5705 5311 IO_CACHE io_cache;
5706 5311 int result = 0;
5707
5708
2/4
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5311 times.
5311 if ((fd = my_open(fname, O_CREAT | O_RDWR, MYF(MY_WME))) < 0) {
5709 LogErr(ERROR_LEVEL, ER_AUTO_OPTIONS_FAILED, "file", fname, my_errno());
5710 return 1;
5711 }
5712
5713
2/4
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5311 times.
5311 if (init_io_cache(&io_cache, fd, IO_SIZE * 2, WRITE_CACHE, 0L, false,
5714 MYF(MY_WME))) {
5715 LogErr(ERROR_LEVEL, ER_AUTO_OPTIONS_FAILED, "a cache on ", fname,
5716 my_errno());
5717 my_close(fd, MYF(MY_WME));
5718 return 1;
5719 }
5720
5721
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 my_b_seek(&io_cache, 0L);
5722
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 my_b_printf(&io_cache, "%s\n", "[auto]");
5723
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 my_b_printf(&io_cache, "server-uuid=%s\n", server_uuid);
5724
5725
5/10
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5311 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5311 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5311 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5311 times.
5311 if (flush_io_cache(&io_cache) || my_sync(fd, MYF(MY_WME))) result = 1;
5726
5727
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 my_close(fd, MYF(MY_WME));
5728
1/2
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
5311 end_io_cache(&io_cache);
5729 5311 return result;
5730 }
5731
5732 /**
5733 File 'auto.cnf' resides in the data directory to hold values of options that
5734 server evaluates itself and that needs to be durable to sustain the server
5735 restart. There is only a section ['auto'] in the file. All these options are
5736 in the section. Only one option exists now, it is server_uuid.
5737 Note, the user may not supply any literal value to these auto-options, and
5738 only allowed to trigger (re)evaluation.
5739 For instance, 'server_uuid' value will be evaluated and stored if there is
5740 no corresponding line in the file.
5741 Because of the specifics of the auto-options, they need separate storage.
5742 Meanwhile, it is the 'auto.cnf' that has the same structure as 'my.cnf'.
5743
5744 @todo consider to implement sql-query-able persistent storage by WL#5279.
5745 @return Return 0 or 1 if an error occurred.
5746 */
5747 12036 static int init_server_auto_options() {
5748 12036 bool flush = false;
5749 char fname[FN_REFLEN];
5750 12036 char name[] = "auto";
5751 12036 char *name_ptr = name;
5752 12036 const char *groups[] = {"auto", nullptr};
5753 12036 char *uuid = nullptr;
5754 12036 my_option auto_options[] = {
5755 {"server-uuid", 0, "", &uuid, &uuid, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
5756 0, nullptr, 0, nullptr},
5757 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
5758 12036 0, nullptr, 0, nullptr}};
5759
5760
1/2
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
12036 DBUG_TRACE;
5761
5762
2/4
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12036 times.
12036 if (nullptr == fn_format(fname, "auto.cnf", mysql_real_data_home_ptr, "",
5763 MY_UNPACK_FILENAME | MY_SAFE_PATH))
5764 return 1;
5765
5766 /* load_defaults require argv[0] is not null */
5767 12036 char **argv = &name_ptr;
5768 12036 int argc = 1;
5769
3/4
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 12035 times.
12036 if (!check_file_permissions(fname, false)) {
5770 /*
5771 Found a world writable file hence removing it as it is dangerous to write
5772 a new UUID into the same file.
5773 */
5774
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 my_delete(fname, MYF(MY_WME));
5775
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_WRITABLE_CONFIG_REMOVED, fname);
5776 }
5777
5778 /* load all options in 'auto.cnf'. */
5779 12036 MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
5780
2/4
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12036 times.
12036 if (my_load_defaults(fname, groups, &argc, &argv, &alloc, nullptr)) return 1;
5781
5782
2/4
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12036 times.
12036 if (handle_options(&argc, &argv, auto_options, mysqld_get_one_option))
5783 return 1;
5784
5785
3/8
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12036 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12036 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12036 DBUG_PRINT("info", ("uuid=%p=%s server_uuid=%s", uuid, uuid, server_uuid));
5786
2/2
✓ Branch 0 taken 6725 times.
✓ Branch 1 taken 5311 times.
12036 if (uuid) {
5787
2/4
✓ Branch 0 taken 6725 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6725 times.
6725 if (!binary_log::Uuid::is_valid(uuid, binary_log::Uuid::TEXT_LENGTH)) {
5788 LogErr(ERROR_LEVEL, ER_UUID_INVALID);
5789 goto err;
5790 }
5791 /*
5792 Uuid::is_valid() cannot do strict check on the length as it will be
5793 called by GTID::is_valid() as well (GTID = UUID:seq_no). We should
5794 explicitly add the *length check* here in this function.
5795
5796 If UUID length is less than '36' (UUID_LENGTH), that error case would have
5797 got caught in above is_valid check. The below check is to make sure that
5798 length is not greater than UUID_LENGTH i.e., there are no extra characters
5799 (Garbage) at the end of the valid UUID.
5800 */
5801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6725 times.
6725 if (strlen(uuid) > UUID_LENGTH) {
5802 LogErr(ERROR_LEVEL, ER_UUID_SCRUB, UUID_LENGTH);
5803 goto err;
5804 }
5805 6725 strcpy(server_uuid, uuid);
5806 } else {
5807
3/8
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5311 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5311 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
5311 DBUG_PRINT("info", ("generating server_uuid"));
5808 5311 flush = true;
5809 /* server_uuid will be set in the function */
5810
2/4
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5311 times.
5311 if (generate_server_uuid()) goto err;
5811
3/8
✓ Branch 0 taken 5311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5311 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5311 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
5311 DBUG_PRINT("info", ("generated server_uuid=%s", server_uuid));
5812
3/4
✓ Branch 0 taken 5014 times.
✓ Branch 1 taken 297 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5014 times.
5311 if (opt_initialize || opt_initialize_insecure) {
5813
8/16
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 297 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 297 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 297 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 297 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 297 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 297 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 297 times.
✗ Branch 15 not taken.
297 LogErr(INFORMATION_LEVEL, ER_CREATING_NEW_UUID_FIRST_START, server_uuid);
5814
5815 } else {
5816
8/16
✓ Branch 0 taken 5014 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5014 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5014 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5014 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5014 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5014 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5014 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5014 times.
✗ Branch 15 not taken.
5014 LogErr(WARNING_LEVEL, ER_CREATING_NEW_UUID, server_uuid);
5817 }
5818 }
5819
5820
3/4
✓ Branch 0 taken 5311 times.
✓ Branch 1 taken 6725 times.
✓ Branch 2 taken 5311 times.
✗ Branch 3 not taken.
12036 if (flush) return flush_auto_options(fname);
5821 6725 return 0;
5822 err:
5823 return 1;
5824 12036 }
5825
5826 23732 static bool initialize_storage_engine(const char *se_name, const char *se_kind,
5827 plugin_ref *dest_plugin) {
5828 23732 LEX_CSTRING name = {se_name, strlen(se_name)};
5829 plugin_ref plugin;
5830 handlerton *hton;
5831
2/4
✓ Branch 0 taken 23732 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23732 times.
✗ Branch 3 not taken.
23732 if ((plugin = ha_resolve_by_name(nullptr, &name, false)))
5832 23732 hton = plugin_data<handlerton *>(plugin);
5833 else {
5834 LogErr(ERROR_LEVEL, ER_UNKNOWN_UNSUPPORTED_STORAGE_ENGINE, se_name);
5835 return true;
5836 }
5837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23732 times.
23732 if (!ha_storage_engine_is_enabled(hton)) {
5838 if (!opt_initialize) {
5839 LogErr(ERROR_LEVEL, ER_DEFAULT_SE_UNAVAILABLE, se_kind, se_name);
5840 return true;
5841 }
5842 assert(*dest_plugin);
5843 } else {
5844 /*
5845 Need to unlock as global_system_variables.table_plugin
5846 was acquired during plugin_register_builtin_and_init_core_se()
5847 */
5848 23732 plugin_ref old_dest_plugin = *dest_plugin;
5849 23732 *dest_plugin = plugin;
5850
1/2
✓ Branch 0 taken 23732 times.
✗ Branch 1 not taken.
23732 plugin_unlock(nullptr, old_dest_plugin);
5851 }
5852 23732 return false;
5853 }
5854
5855 12098 static void setup_error_log() {
5856 /* Setup logs */
5857
5858 /*
5859 Enable old-fashioned error log, except when the user has requested
5860 help information. Since the implementation of plugin server
5861 variables the help output is now written much later.
5862
5863 log_error_dest can be:
5864 disabled_my_option --log-error was not used or --log-error=
5865 "" --log-error without arguments (no '=')
5866 filename --log-error=filename
5867 */
5868
5869 #ifdef _WIN32
5870 /*
5871 Enable the error log file only if console option is not specified
5872 and --help is not used.
5873 */
5874 bool log_errors_to_file = !is_help_or_validate_option() && !opt_console;
5875 #else
5876 /*
5877 Enable the error log file only if --log-error=filename or --log-error
5878 was used. Logging to file is disabled by default unlike on Windows.
5879 */
5880 bool log_errors_to_file =
5881
4/4
✓ Branch 0 taken 12079 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 857 times.
✓ Branch 3 taken 11222 times.
12098 !is_help_or_validate_option() && (log_error_dest != disabled_my_option);
5882 #endif
5883
5884
2/2
✓ Branch 0 taken 857 times.
✓ Branch 1 taken 11241 times.
12098 if (log_errors_to_file) {
5885 // Construct filename if no filename was given by the user.
5886
3/4
✓ Branch 0 taken 855 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 855 times.
857 if (!log_error_dest[0] || log_error_dest == disabled_my_option) {
5887 #ifdef _WIN32
5888 const char *filename = pidfile_name;
5889 #else
5890 2 const char *filename = default_logfile_name;
5891 #endif
5892 2 fn_format(errorlog_filename_buff, filename, mysql_real_data_home, ".err",
5893 MY_REPLACE_EXT | /* replace '.<domain>' by '.err', bug#4997 */
5894 MY_REPLACE_DIR);
5895 2 } else
5896 855 fn_format(errorlog_filename_buff, log_error_dest, mysql_data_home, ".err",
5897 MY_UNPACK_FILENAME);
5898 /*
5899 log_error_dest may have been set to disabled_my_option or "" if no
5900 argument was passed, but we need to show the real name in SHOW VARIABLES.
5901 */
5902 857 log_error_dest = errorlog_filename_buff;
5903
5904 #ifndef _WIN32
5905 // Create backup stream to stdout if daemonizing and connected to tty
5906
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 855 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 857 times.
857 if (opt_daemonize && isatty(STDOUT_FILENO)) {
5907 nstdout = fdopen(dup(STDOUT_FILENO), "a");
5908 if (nstdout == nullptr) {
5909 LogErr(ERROR_LEVEL, ER_DUP_FD_OPEN_FAILED, "stdout", strerror(errno));
5910 unireg_abort(MYSQLD_ABORT_EXIT);
5911 }
5912 // Display location of error log file on stdout if connected to tty
5913 fprintf(nstdout, "mysqld will log errors to %s\n",
5914 errorlog_filename_buff);
5915 }
5916 #endif /* ndef _WIN32 */
5917
5918
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 855 times.
857 if (open_error_log(errorlog_filename_buff, false))
5919 2 unireg_abort(MYSQLD_ABORT_EXIT);
5920
5921 #ifdef _WIN32
5922 // FreeConsole(); // Remove window
5923 #endif /* _WIN32 */
5924 } else {
5925 // We are logging to stderr and SHOW VARIABLES should reflect that.
5926 11241 log_error_dest = "stderr";
5927 }
5928 12096 }
5929
5930 /**
5931 Try to set the error logging pipeline from @@global.log_error_services.
5932 Try to read the previous run's error log and make it available in
5933 performance_schema.error_log.
5934 Flush the buffered error messages to performance schema and to configured
5935 services, and end error log buffering.
5936 On success, log_error_stage_current becomes
5937 LOG_ERROR_STAGE_COMPONENTS_AND_PFS.
5938
5939 @retval 0 Success
5940 @retval 1 Log pipeline not set up as requested. Caller should abort.
5941 */
5942 12056 static int setup_error_log_components() {
5943 12056 int ret = 1; // failure unless otherwise specified
5944
5945 /*
5946 LOCK_plugin needs to be valid in case we implicitly load
5947 components below that install component-variables.
5948 (Otherwise, an assert will fire as the variable-install
5949 code examines the locks, but plugins have not yet been
5950 initialized.)
5951 */
5952 12056 mysql_mutex_init(0, &LOCK_plugin, MY_MUTEX_INIT_FAST);
5953
5954 /*
5955 Now that we have the component infrastructure, check
5956 --log-error-services=... -- is it well-formed, and do
5957 the requested services exist?
5958 As a side-effect, this will load any external logging
5959 components listed.
5960 This way when we run get_options(), any system variables
5961 provided by those logging components will already be
5962 available.
5963
5964 This function loads its components directly without
5965 going through the layer that persists component set-up
5966 in mysql.component. This way, our logging components can
5967 be activated before rather than after InnoDB becomes
5968 available, and InnoDB start-up messages can be logged
5969 using components as a result.
5970 */
5971
2/2
✓ Branch 0 taken 12054 times.
✓ Branch 1 taken 2 times.
12056 if (log_builtins_error_stack(opt_log_error_services, true, nullptr) == 0) {
5972 // Syntax is OK and services exist; let's try to initialize them:
5973 size_t pos;
5974
5975
2/4
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12054 times.
12054 if (log_builtins_error_stack(opt_log_error_services, false, &pos) < 0) {
5976 char *problem = opt_log_error_services; /* purecov: begin inspected */
5977 const std::string var_name = "log_error_services";
5978
5979 /*
5980 We failed to set the requested configuration. This can happen
5981 e.g. when a given log-writer does not have sufficient permissions
5982 to open its log files. pos should mark the position in the
5983 configuration string where we ran into trouble. Make a char-pointer
5984 from it so we can inform the user what log-service we could not
5985 initialize.
5986 */
5987 if (pos < strlen(opt_log_error_services))
5988 problem = &((char *)opt_log_error_services)[pos];
5989
5990 /*
5991 We could not set the requested pipeline.
5992 Try to fall back to default error logging stack
5993 (by looking up the system variable for this configuration
5994 item and extracting the default value from it).
5995 If that's impossible, print diagnostics, then exit.
5996 */
5997 sys_var *var = find_static_system_variable(var_name);
5998
5999 if (var != nullptr) {
6000 // We found the system variable, now extract the default value:
6001 opt_log_error_services = (char *)var->get_default();
6002 if (log_builtins_error_stack(opt_log_error_services, false, nullptr) >=
6003 0) {
6004 /*
6005 We managed to set the default pipeline. Now log what was wrong
6006 about the user-supplied value, then shut down.
6007 */
6008 flush_error_log_messages();
6009 LogErr(ERROR_LEVEL, ER_CANT_START_ERROR_LOG_SERVICE, var_name.c_str(),
6010 problem);
6011 goto failure;
6012 }
6013 /*
6014 If we arrive here, the user-supplied value was valid, but could
6015 not be set. The default value was found, but also could not be
6016 set. Something is very wrong. Fall-through to below where we
6017 low-level write diagnostics, then abort.
6018 */
6019 }
6020
6021 /*
6022 We failed to set the default error logging stack (or failed to look
6023 up the default setting). At this point, we don't know whether ANY of
6024 the requested sinks work, so our best bet is to write directly to the
6025 error stream. Then, we abort.
6026 */
6027 {
6028 char buff[512];
6029 size_t len;
6030
6031 len = snprintf(buff, sizeof(buff),
6032 ER_DEFAULT(ER_CANT_START_ERROR_LOG_SERVICE),
6033 var_name.c_str(), problem);
6034 len = std::min(len, sizeof(buff) - 1);
6035
6036 // Trust nothing. Write directly. Quit.
6037 log_write_errstream(buff, len);
6038
6039 goto failure;
6040 } /* purecov: end */
6041 } // value was OK, but could not be set
6042 // If we arrive here, the value was OK, and was set successfully.
6043 } else {
6044 /*
6045 We were given an illegal value at start-up, so the default was
6046 used instead. Let's now point our variable back at the default
6047 (i.e. the value actually used) so SELECT @@GLOBAL.log_error_services
6048 will render correct results.
6049 */
6050
6051
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 sys_var *var = find_static_system_variable("log_error_services");
6052 2 char *default_services = nullptr;
6053
6054
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 if ((var != nullptr) &&
6055
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ((default_services = (char *)var->get_default()) != nullptr))
6056 2 log_builtins_error_stack(default_services, false, nullptr);
6057
6058 // Report that we're falling back to the default value.
6059
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(WARNING_LEVEL, ER_CANNOT_SET_LOG_ERROR_SERVICES,
6060 opt_log_error_services);
6061
6062
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (default_services != nullptr) opt_log_error_services = default_services;
6063 }
6064
6065 /*
6066 We'll want to flush whatever log-events we buffered during start-up
6067 to the now available components in a moment. To that end, we now
6068 switch from saving log-events in a buffer to processing them via
6069 the logging-pipeline.
6070 Not switching processors here would result in flushing the buffer
6071 into the buffer.
6072 */
6073 12056 log_line_process_hook_set(log_line_error_stack_run);
6074 12056 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS);
6075
6076 /*
6077 Set-up the error-log table, performance_schema.error_log.
6078 Try to populate it with previous runs' error-log and events
6079 buffered up to this point.
6080
6081 log_error_read_log_init() initializes the ring-buffer for
6082 performance_schema.error_log.
6083
6084 log_error_read_log() reads an existing error-log (of whatever formatting).
6085
6086 LOG_ERROR_STAGE_COMPONENTS_AND_PFS flags the error logging
6087 stack as fully operational, loadable components and all.
6088 In this mode, all submitted error-log events are also automatically
6089 added to performance_schema.error_log.
6090
6091 flush_error_log_messages() is called once any configured loadable
6092 error log-services are available. It flushes all buffered log-events
6093 to the log-services the user actually wants.
6094 If LOG_ERROR_STAGE_COMPONENTS_AND_PFS is set, also add the
6095 flushed events to performance_schema.error_log.
6096 */
6097
2/4
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12056 times.
✗ Branch 3 not taken.
12056 assert((log_error_dest != nullptr) && (log_error_dest[0] != '\0'));
6098
6099
2/2
✓ Branch 0 taken 11209 times.
✓ Branch 1 taken 847 times.
12056 if (!strcmp(log_error_dest, "stderr")) {
6100 // If we logging to stderr, there will be no log-file to read.
6101 // As this is a common case in mysql-test-run, we offer a fallback.
6102
6103 // Let the user know we cannot provide info from previous runs.
6104
7/14
✓ Branch 0 taken 11209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11209 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11209 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11209 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11209 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11209 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11209 times.
✗ Branch 13 not taken.
11209 LogErr(INFORMATION_LEVEL, ER_ERROR_LOG_DESTINATION_NOT_A_FILE, "stderr");
6105 // init logging to pfs
6106 11209 log_error_read_log_init();
6107 // flag log-stack as ready and enable logging to pfs
6108 11209 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS_AND_PFS);
6109 // flush messages, sending a copy to pfs
6110 11209 flush_error_log_messages();
6111 } else {
6112 // We're logging to a named file.
6113
6114 /*
6115 Flush messages, not sending a copy to pfs -- we'll get the info
6116 from the log-file anyway when we try to restore the previous run's
6117 info.
6118 */
6119 847 flush_error_log_messages();
6120 /*
6121 Try to load error log events from the previous run (if available)
6122 and that from the current start-up into performance_schema.error_log.
6123 */
6124
1/2
✓ Branch 0 taken 847 times.
✗ Branch 1 not taken.
847 if (!log_error_read_log_init()) log_error_read_log(log_error_dest);
6125 // flag log-stack as ready and enable logging to pfs
6126 847 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS_AND_PFS);
6127 }
6128
6129 12056 ret = 0; // Success!
6130
6131 12056 failure:
6132
6133 /*
6134 Destroy lock so plugin_register_early_plugins() > plugin_init_internals()
6135 can properly set up all plugin-related things together below.
6136 */
6137 12056 mysql_mutex_destroy(&LOCK_plugin);
6138
6139 12056 return ret;
6140 }
6141
6142 #if defined(MYSQL_ICU_DATADIR)
6143
6144 // For "bundled" ICU:
6145 // Verify that we can find <directory_path>/icudt69l
6146 // and <directory_path>/icudt69l/unames.icu
6147 // or <directory_path>/icudt69b on Sparc
6148 11768 static bool icu_data_directory_is_valid(const char *directory_path) {
6149 MY_STAT stat_info;
6150
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 bool directory_exists = mysql_file_stat(key_file_misc, directory_path,
6151 11768 &stat_info, MYF(0)) != nullptr;
6152
2/2
✓ Branch 0 taken 11757 times.
✓ Branch 1 taken 11 times.
11768 if (directory_exists) {
6153 char icudt_path[FN_REFLEN];
6154
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 fn_format(icudt_path, ICUDT_DIR, directory_path, "", 0);
6155 bool icudt_dir_exists =
6156
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 mysql_file_stat(key_file_misc, icudt_path, &stat_info, MYF(0));
6157
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 if (icudt_dir_exists) {
6158 char icunames_path[FN_REFLEN];
6159
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 fn_format(icunames_path, "unames.icu", icudt_path, "", 0);
6160 bool icu_unames_exists =
6161
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 mysql_file_stat(key_file_misc, icunames_path, &stat_info, MYF(0));
6162
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 if (icu_unames_exists) {
6163 11757 return true;
6164 }
6165 }
6166 }
6167 11 return false;
6168 }
6169
6170 // For "bundled" ICU:
6171 // Look for icudt69l.lnk in build directory.
6172 11768 static char *get_icu_data_directory_in_build_dir(char *to) {
6173 char icudt_path[FN_REFLEN];
6174
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 fn_format(icudt_path, ICUDT_DIR, mysql_home, ".lnk", 0);
6175 MY_STAT stat_info;
6176 bool icudt_lnk_exists =
6177
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 mysql_file_stat(key_file_misc, icudt_path, &stat_info, MYF(0)) != nullptr;
6178
2/2
✓ Branch 0 taken 11757 times.
✓ Branch 1 taken 11 times.
11768 if (icudt_lnk_exists) {
6179
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 File file = mysql_file_open(key_file_misc, icudt_path, O_RDONLY, 0);
6180
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 if (file != -1) {
6181 char icudt_lnk_contents[FN_REFLEN];
6182 size_t num_bytes_read =
6183
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 mysql_file_read(file, reinterpret_cast<uchar *>(icudt_lnk_contents),
6184 sizeof(icudt_lnk_contents), 0);
6185
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 mysql_file_close(file, 0);
6186
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 if (num_bytes_read != MY_FILE_ERROR) {
6187 11757 icudt_lnk_contents[num_bytes_read] = '\0';
6188 11757 memcpy(to, icudt_lnk_contents, num_bytes_read + 1);
6189 11757 return to;
6190 }
6191 }
6192 }
6193 11 return nullptr;
6194 }
6195
6196 // For "bundled" ICU:
6197 // Look for MYSQL_ICU_DATADIR which depends on INSTALL_PRIV_LIBDIR
6198 11 static char *get_icu_data_directory_in_install_dir(char *to) {
6199 char buff[FN_REFLEN];
6200
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 const char *mysql_icu_datadir = get_relative_path(MYSQL_ICU_DATADIR);
6201
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if (test_if_hard_path(mysql_icu_datadir))
6202 strmake(buff, mysql_icu_datadir, sizeof(buff) - 1);
6203 else
6204
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 strxnmov(buff, sizeof(buff) - 1, mysql_home, mysql_icu_datadir, NullS);
6205
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 convert_dirname(buff, buff, NullS);
6206 11 memcpy(to, buff, sizeof(buff));
6207 11 return to;
6208 }
6209
6210 // Where to look for data files for "bundled" ICU:
6211 // Look in environment ICU_DATA.
6212 // In a build sandbox we expect cmake to write a .lnk file.
6213 // In an install directory, we look in MYSQL_ICU_DATADIR.
6214 11768 static void init_icu_data_directory() {
6215 // Use environment variable if available.
6216 11768 const char *env_icu_data = getenv("ICU_DATA");
6217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11768 times.
11768 if (env_icu_data != nullptr) {
6218 if (icu_data_directory_is_valid(env_icu_data)) {
6219 11757 return;
6220 }
6221 LogErr(WARNING_LEVEL, ER_REGEXP_MISSING_ICU_DATADIR, env_icu_data);
6222 // Continue, looking for ICU in build or install directory.
6223 }
6224
6225 char build_dir_buffer[FN_REFLEN];
6226
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 const char *in_build = get_icu_data_directory_in_build_dir(build_dir_buffer);
6227
6/8
✓ Branch 0 taken 11757 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 11757 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11757 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11757 times.
✓ Branch 7 taken 11 times.
11768 if (in_build != nullptr && icu_data_directory_is_valid(in_build)) {
6228
1/2
✓ Branch 0 taken 11757 times.
✗ Branch 1 not taken.
11757 u_setDataDirectory(in_build);
6229 11757 return;
6230 }
6231 char install_dir_buffer[FN_REFLEN];
6232 const char *in_install =
6233
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 get_icu_data_directory_in_install_dir(install_dir_buffer);
6234
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 11 times.
11 if (in_install != nullptr && icu_data_directory_is_valid(in_install)) {
6235 u_setDataDirectory(in_install);
6236 return;
6237 }
6238
8/16
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 11 times.
✗ Branch 15 not taken.
11 LogErr(WARNING_LEVEL, ER_REGEXP_MISSING_ICU_DATADIR, install_dir_buffer);
6239 }
6240
6241 #endif // MYSQL_ICU_DATADIR
6242
6243 12058 static int init_server_components() {
6244
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 buffered_error_log.resize(buffered_error_log_size * 1024);
6245
6246
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 DBUG_TRACE;
6247 /*
6248 We need to call each of these following functions to ensure that
6249 all things are initialized so that unireg_abort() doesn't fail
6250 */
6251
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 mdl_init();
6252
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 partitioning_init();
6253
5/10
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12058 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12058 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12058 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 12058 times.
12058 if (table_def_init() || hostname_cache_init(host_cache_size))
6254 unireg_abort(MYSQLD_ABORT_EXIT);
6255
6256 /*
6257 This load function has to be called after the opt_plugin_dir variable
6258 is initialized else it will fail to load.
6259 The unload of these components will be done by minimal_chassis_deinit().
6260 So, no need to call unload of these components.
6261 Since, it is an optional component required for GR, audit log etc. The
6262 error check of the service availability has to be done by those
6263 plugins/components.
6264 */
6265
6/6
✓ Branch 0 taken 12040 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11743 times.
✓ Branch 3 taken 297 times.
✓ Branch 4 taken 11743 times.
✓ Branch 5 taken 315 times.
12058 if (!is_help_or_validate_option() && !opt_initialize)
6266
1/2
✓ Branch 0 taken 11743 times.
✗ Branch 1 not taken.
11743 dynamic_loader_srv->load(component_urns, NUMBER_OF_COMPONENTS);
6267
6268 /*
6269 Timers not needed if only starting with --help.
6270 */
6271
2/2
✓ Branch 0 taken 12040 times.
✓ Branch 1 taken 18 times.
12058 if (!is_help_or_validate_option()) {
6272
2/4
✓ Branch 0 taken 12040 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12040 times.
12040 if (my_timer_initialize())
6273 LogErr(ERROR_LEVEL, ER_CANT_INIT_TIMER, errno);
6274 else
6275 12040 have_statement_timeout = SHOW_OPTION_YES;
6276 }
6277
6278
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 randominit(&sql_rand, (ulong)server_start_time, (ulong)server_start_time / 2);
6279 12058 setup_fpu();
6280
6281
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 init_global_table_stats();
6282
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 init_global_index_stats();
6283
6284
1/2
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
12058 setup_error_log(); // opens the log if needed
6285
6286 12056 enter_cond_hook = thd_enter_cond;
6287 12056 exit_cond_hook = thd_exit_cond;
6288 12056 enter_stage_hook = thd_enter_stage;
6289 12056 set_waiting_for_disk_space_hook = thd_set_waiting_for_disk_space;
6290 12056 is_killed_hook = thd_killed;
6291
6292
1/2
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
12056 xa::Transaction_cache::initialize();
6293
6294 /*
6295 Try to read the previous run's error log and make it available in
6296 performance_schema.error_log. Activate all error logging services
6297 requested by the user in @@global.log_error_services (now that the
6298 component infrastructure is available), flush the buffered error
6299 messages to performance schema and to configured services, and end
6300 error log buffering.
6301
6302 Pre-requisites:
6303 We depend on component_infrastructure_init() and setup_error_log()
6304 above. init_common_variables() additionally gives us a correctly
6305 set up umask etc., and keyring-migration may modify the log-target,
6306 so we wait that out as well. It should be safe to go before the
6307 component-autoload above ("component_urns") for the time being,
6308 but that may not be the case in the future, so we're playing it
6309 safe. Altogether by the time we get here, we're usually within
6310 a second of start-up, with a half-dozen or less messages buffered
6311 if no issues were encountered.
6312 */
6313
2/6
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12056 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12056 if (setup_error_log_components()) unireg_abort(MYSQLD_ABORT_EXIT);
6314
6315
2/4
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12056 times.
12056 if (MDL_context_backup_manager::init()) {
6316 LogErr(ERROR_LEVEL, ER_OOM);
6317 unireg_abort(MYSQLD_ABORT_EXIT);
6318 }
6319
6320 /*
6321 initialize delegates for extension observers, errors have already
6322 been reported in the function
6323 */
6324
2/6
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12056 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12056 if (delegates_init()) unireg_abort(MYSQLD_ABORT_EXIT);
6325
6326 /* need to configure logging before initializing storage engines */
6327
4/4
✓ Branch 0 taken 11408 times.
✓ Branch 1 taken 648 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11407 times.
12056 if (opt_log_replica_updates && !opt_bin_log) {
6328
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--log-replica-updates");
6329 }
6330
4/4
✓ Branch 0 taken 3277 times.
✓ Branch 1 taken 8779 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 3117 times.
12056 if (binlog_format_used && !opt_bin_log)
6331
8/16
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 160 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 160 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 160 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 160 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 160 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 160 times.
✗ Branch 15 not taken.
160 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-format");
6332
6333 /* Check that we have not let the format to unspecified at this point */
6334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12056 times.
12056 assert((uint)global_system_variables.binlog_format <=
6335 array_elements(binlog_format_names) - 1);
6336
6337 12056 opt_server_id_mask = ~ulong(0);
6338 12056 opt_server_id_mask =
6339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12056 times.
12056 (opt_server_id_bits == 32) ? ~ulong(0) : (1 << opt_server_id_bits) - 1;
6340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12056 times.
12056 if (server_id != (server_id & opt_server_id_mask)) {
6341 LogErr(ERROR_LEVEL, ER_SERVERID_TOO_LARGE);
6342 unireg_abort(MYSQLD_ABORT_EXIT);
6343 }
6344
6345
2/2
✓ Branch 0 taken 11446 times.
✓ Branch 1 taken 610 times.
12056 if (opt_bin_log) {
6346 /* Reports an error and aborts, if the --log-bin's path
6347 is a directory.*/
6348
2/2
✓ Branch 0 taken 4146 times.
✓ Branch 1 taken 7300 times.
11446 if (opt_bin_logname &&
6349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4146 times.
4146 opt_bin_logname[strlen(opt_bin_logname) - 1] == FN_LIBCHAR) {
6350 LogErr(ERROR_LEVEL, ER_NEED_FILE_INSTEAD_OF_DIR, "--log-bin",
6351 opt_bin_logname);
6352 unireg_abort(MYSQLD_ABORT_EXIT);
6353 }
6354
6355 /* Reports an error and aborts, if the --log-bin-index's path
6356 is a directory.*/
6357
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11443 times.
11446 if (opt_binlog_index_name &&
6358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 opt_binlog_index_name[strlen(opt_binlog_index_name) - 1] ==
6359 FN_LIBCHAR) {
6360 LogErr(ERROR_LEVEL, ER_NEED_FILE_INSTEAD_OF_DIR, "--log-bin-index",
6361 opt_binlog_index_name);
6362 unireg_abort(MYSQLD_ABORT_EXIT);
6363 }
6364
6365 char buf[FN_REFLEN];
6366 const char *ln;
6367
2/2
✓ Branch 0 taken 4195 times.
✓ Branch 1 taken 7251 times.
11446 if (log_bin_supplied) {
6368 /*
6369 Binary log basename defaults to "`hostname`-bin" name prefix
6370 if --log-bin is used without argument.
6371 */
6372
1/2
✓ Branch 0 taken 4195 times.
✗ Branch 1 not taken.
4195 ln = mysql_bin_log.generate_name(opt_bin_logname, "-bin", buf);
6373 } else {
6374 /*
6375 Binary log basename defaults to "binlog" name prefix
6376 if --log-bin is not used.
6377 */
6378
1/2
✓ Branch 0 taken 7251 times.
✗ Branch 1 not taken.
7251 ln = mysql_bin_log.generate_name(opt_bin_logname, "", buf);
6379 }
6380
6381
5/6
✓ Branch 0 taken 7300 times.
✓ Branch 1 taken 4146 times.
✓ Branch 2 taken 7300 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49 times.
✓ Branch 5 taken 7251 times.
11446 if (!opt_bin_logname && !opt_binlog_index_name && log_bin_supplied) {
6382 /*
6383 User didn't give us info to name the binlog index file.
6384 Picking `hostname`-bin.index like did in 4.x, causes replication to
6385 fail if the hostname is changed later. So, we would like to instead
6386 require a name. But as we don't want to break many existing setups, we
6387 only give warning, not error.
6388 */
6389
8/16
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 49 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 49 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 49 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 49 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 49 times.
✗ Branch 15 not taken.
49 LogErr(INFORMATION_LEVEL, ER_LOG_BIN_BETTER_WITH_NAME, ln);
6390 }
6391
1/2
✓ Branch 0 taken 11446 times.
✗ Branch 1 not taken.
11446 if (ln == buf) {
6392
1/2
✓ Branch 0 taken 11446 times.
✗ Branch 1 not taken.
11446 my_free(opt_bin_logname);
6393
1/2
✓ Branch 0 taken 11446 times.
✗ Branch 1 not taken.
11446 opt_bin_logname = my_strdup(key_memory_opt_bin_logname, buf, MYF(0));
6394 }
6395
6396 /*
6397 Skip opening the index file if we start with --help. This is necessary
6398 to avoid creating the file in an otherwise empty datadir, which will
6399 cause a succeeding 'mysqld --initialize' to fail.
6400 */
6401
3/4
✓ Branch 0 taken 11430 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11446 times.
22876 if (!is_help_or_validate_option() &&
6402
2/4
✓ Branch 0 taken 11430 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11430 times.
11430 mysql_bin_log.open_index_file(opt_binlog_index_name, ln, true)) {
6403 unireg_abort(MYSQLD_ABORT_EXIT);
6404 }
6405 }
6406
6407
2/2
✓ Branch 0 taken 11446 times.
✓ Branch 1 taken 610 times.
12056 if (opt_bin_log) {
6408 /*
6409 opt_bin_logname[0] needs to be checked to make sure opt binlog name is
6410 not an empty string, in case it is an empty string default file
6411 extension will be passed
6412 */
6413
2/2
✓ Branch 0 taken 4195 times.
✓ Branch 1 taken 7251 times.
11446 if (log_bin_supplied) {
6414
1/2
✓ Branch 0 taken 4195 times.
✗ Branch 1 not taken.
4195 log_bin_basename = rpl_make_log_name(
6415 key_memory_MYSQL_BIN_LOG_basename, opt_bin_logname,
6416 default_logfile_name,
6417
2/4
✓ Branch 0 taken 4195 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4195 times.
✗ Branch 3 not taken.
4195 (opt_bin_logname && opt_bin_logname[0]) ? "" : "-bin");
6418 } else {
6419 7251 log_bin_basename =
6420
1/2
✓ Branch 0 taken 7251 times.
✗ Branch 1 not taken.
7251 rpl_make_log_name(key_memory_MYSQL_BIN_LOG_basename, opt_bin_logname,
6421 default_binlogfile_name, "");
6422 }
6423
6424 11446 log_bin_index =
6425
1/2
✓ Branch 0 taken 11446 times.
✗ Branch 1 not taken.
11446 rpl_make_log_name(key_memory_MYSQL_BIN_LOG_index, opt_binlog_index_name,
6426 log_bin_basename, ".index");
6427
6428
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11443 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
11446 if ((!opt_binlog_index_name || !opt_binlog_index_name[0]) &&
6429
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 log_bin_index) {
6430 22886 strmake(default_binlog_index_name,
6431
2/4
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11443 times.
✗ Branch 3 not taken.
11443 log_bin_index + dirname_length(log_bin_index),
6432 FN_REFLEN + index_ext_length - 1);
6433 11443 opt_binlog_index_name = default_binlog_index_name;
6434 }
6435
6436
2/4
✓ Branch 0 taken 11446 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11446 times.
11446 if (log_bin_basename == nullptr || log_bin_index == nullptr) {
6437 LogErr(ERROR_LEVEL, ER_RPL_CANT_MAKE_PATHS, (int)FN_REFLEN, (int)FN_LEN);
6438 unireg_abort(MYSQLD_ABORT_EXIT);
6439 }
6440 }
6441
6442
3/8
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12056 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12056 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12056 DBUG_PRINT("debug",
6443 ("opt_bin_logname: %s, opt_relay_logname: %s, pidfile_name: %s",
6444 opt_bin_logname, opt_relay_logname, pidfile_name));
6445
6446 /*
6447 opt_relay_logname[0] needs to be checked to make sure opt relaylog name is
6448 not an empty string, in case it is an empty string default file
6449 extension will be passed
6450 */
6451
1/2
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
12056 relay_log_basename = rpl_make_log_name(
6452 key_memory_MYSQL_RELAY_LOG_basename, opt_relay_logname,
6453 default_logfile_name,
6454
3/4
✓ Branch 0 taken 3184 times.
✓ Branch 1 taken 8872 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3184 times.
12056 (opt_relay_logname && opt_relay_logname[0]) ? "" : relay_ext);
6455
6456
3/4
✓ Branch 0 taken 3184 times.
✓ Branch 1 taken 8872 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3184 times.
12056 if (!opt_relay_logname || !opt_relay_logname[0]) {
6457
1/2
✓ Branch 0 taken 8872 times.
✗ Branch 1 not taken.
8872 if (relay_log_basename) {
6458 17744 strmake(default_relaylogfile_name,
6459
2/4
✓ Branch 0 taken 8872 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8872 times.
✗ Branch 3 not taken.
8872 relay_log_basename + dirname_length(relay_log_basename),
6460 FN_REFLEN + relay_ext_length - 1);
6461 8872 opt_relay_logname = default_relaylogfile_name;
6462 }
6463 } else
6464 3184 opt_relay_logname_supplied = true;
6465
6466
1/2
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
12056 if (relay_log_basename != nullptr)
6467
1/2
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
12056 relay_log_index = rpl_make_log_name(key_memory_MYSQL_RELAY_LOG_index,
6468 opt_relaylog_index_name,
6469 relay_log_basename, ".index");
6470
6471
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12048 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
12056 if (!opt_relaylog_index_name || !opt_relaylog_index_name[0]) {
6472
1/2
✓ Branch 0 taken 12048 times.
✗ Branch 1 not taken.
12048 if (relay_log_index) {
6473 24096 strmake(default_relaylog_index_name,
6474
2/4
✓ Branch 0 taken 12048 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12048 times.
✗ Branch 3 not taken.
12048 relay_log_index + dirname_length(relay_log_index),
6475 FN_REFLEN + relay_ext_length + index_ext_length - 1);
6476 12048 opt_relaylog_index_name = default_relaylog_index_name;
6477 }
6478 } else
6479 8 opt_relaylog_index_name_supplied = true;
6480
6481
2/4
✓ Branch 0 taken 12056 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12056 times.
12056 if (relay_log_basename == nullptr || relay_log_index == nullptr) {
6482 LogErr(ERROR_LEVEL, ER_RPL_CANT_MAKE_PATHS, (int)FN_REFLEN, (int)FN_LEN);
6483 unireg_abort(MYSQLD_ABORT_EXIT);
6484 }
6485
6486
2/2
✓ Branch 0 taken 11446 times.
✓ Branch 1 taken 610 times.
12056 if (log_bin_basename != nullptr &&
6487
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11444 times.
11446 !strcmp(log_bin_basename, relay_log_basename)) {
6488 2 const int bin_ext_length = 4;
6489 char default_binlogfile_name_from_hostname[FN_REFLEN + bin_ext_length];
6490 /* Generate default bin log file name. */
6491
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 strmake(default_binlogfile_name_from_hostname, default_logfile_name,
6492 FN_REFLEN - 1);
6493 2 strcat(default_binlogfile_name_from_hostname, "-bin");
6494
6495
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!default_relaylogfile_name[0]) {
6496 /* Generate default relay log file name. */
6497
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 strmake(default_relaylogfile_name, default_logfile_name, FN_REFLEN - 1);
6498 2 strcat(default_relaylogfile_name, relay_ext);
6499 }
6500 /*
6501 Reports an error and aborts, if the same base name is specified
6502 for both binary and relay logs.
6503 */
6504
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(ERROR_LEVEL, ER_RPL_CANT_HAVE_SAME_BASENAME, log_bin_basename,
6505 "--log-bin", default_binlogfile_name,
6506 default_binlogfile_name_from_hostname, "--relay-log",
6507 default_relaylogfile_name);
6508
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
6509 }
6510
6511
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12048 times.
12054 if (global_system_variables.binlog_row_value_options != 0) {
6512 6 const char *msg = nullptr;
6513 6 longlong err = ER_BINLOG_ROW_VALUE_OPTION_IGNORED;
6514
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (!opt_bin_log)
6515 1 msg = "the binary log is disabled";
6516
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 else if (global_system_variables.binlog_format == BINLOG_FORMAT_STMT)
6517 1 msg = "binlog_format=STATEMENT";
6518
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 else if (log_bin_use_v1_row_events) {
6519 1 msg = "binlog_row_value_options=PARTIAL_JSON";
6520 1 err = ER_BINLOG_USE_V1_ROW_EVENTS_IGNORED;
6521
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 } else if (global_system_variables.binlog_row_image ==
6522 BINLOG_ROW_IMAGE_FULL) {
6523 1 msg = "binlog_row_image=FULL";
6524 1 err = ER_BINLOG_ROW_VALUE_OPTION_USED_ONLY_FOR_AFTER_IMAGES;
6525 }
6526
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (msg) {
6527
2/3
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
4 switch (err) {
6528 3 case ER_BINLOG_ROW_VALUE_OPTION_IGNORED:
6529 case ER_BINLOG_ROW_VALUE_OPTION_USED_ONLY_FOR_AFTER_IMAGES:
6530
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, err, msg, "PARTIAL_JSON");
6531 3 break;
6532 1 case ER_BINLOG_USE_V1_ROW_EVENTS_IGNORED:
6533
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, err, msg);
6534 1 break;
6535 default:
6536 assert(0); /* purecov: deadcode */
6537 }
6538 }
6539 }
6540
6541 /* call ha_init_key_cache() on all key caches to init them */
6542
1/2
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
12054 process_key_caches(&ha_init_key_cache);
6543
6544 /* Allow storage engine to give real error messages */
6545
2/4
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12054 times.
12054 if (ha_init_errors()) return 1;
6546
6547
2/4
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12054 times.
12054 if (gtid_server_init()) {
6548 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_GTID);
6549 unireg_abort(MYSQLD_ABORT_EXIT);
6550 }
6551
6552
4/4
✓ Branch 0 taken 11406 times.
✓ Branch 1 taken 648 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11404 times.
12054 if (opt_log_replica_updates && replicate_same_server_id) {
6553
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 if (opt_bin_log && global_gtid_mode.get() != Gtid_mode::ON) {
6554 LogErr(ERROR_LEVEL, ER_RPL_INFINITY_DENIED);
6555 unireg_abort(MYSQLD_ABORT_EXIT);
6556 } else
6557
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(WARNING_LEVEL, ER_RPL_INFINITY_IGNORED);
6558 }
6559
6560 {
6561 /*
6562 We have to call a function in log_resource.cc, or its references
6563 won't be visible to plugins.
6564 */
6565 #ifndef NDEBUG
6566 int dummy =
6567 #endif
6568
1/2
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
12054 Log_resource::dummy_function_to_ensure_we_are_linked_into_the_server();
6569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12054 times.
12054 assert(dummy == 1);
6570 }
6571
6572 /*
6573 We need to initialize the UDF globals early before reading the proc table
6574 and before the server component initialization to allow other components
6575 to register their UDFs at init time and de-register them at deinit time.
6576 */
6577
1/2
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
12054 udf_init_globals();
6578
6579 /*
6580 Set tc_log to point to TC_LOG_DUMMY early in order to allow plugin_init()
6581 to commit attachable transaction after reading from mysql.plugin table.
6582 If necessary tc_log will be adjusted to point to correct TC_LOG instance
6583 later.
6584 */
6585 12054 tc_log = &tc_log_dummy;
6586
6587 /*
6588 Each server should have one UUID. We will create it automatically, if it
6589 does not exist. It should be initialized before opening binlog file. Because
6590 server's uuid will be stored into the new binlog file.
6591 */
6592
5/8
✓ Branch 0 taken 12036 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 12036 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12036 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12054 times.
12054 if (!is_help_or_validate_option() && init_server_auto_options()) {
6593 LogErr(ERROR_LEVEL, ER_CANT_CREATE_UUID);
6594 unireg_abort(MYSQLD_ABORT_EXIT);
6595 }
6596
6597 /*Load early plugins */
6598
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12036 times.
✓ Branch 2 taken 12054 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12054 times.
12054 if (plugin_register_early_plugins(&remaining_argc, remaining_argv,
6599 12054 (is_help_or_validate_option())
6600 ? PLUGIN_INIT_SKIP_INITIALIZATION
6601 : 0)) {
6602 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_EARLY_PLUGINS);
6603 unireg_abort(1);
6604 }
6605
6606 /* Load builtin plugins, initialize MyISAM, CSV and InnoDB */
6607
3/4
✓ Branch 0 taken 12054 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 12036 times.
12054 if (plugin_register_builtin_and_init_core_se(&remaining_argc,
6608 remaining_argv)) {
6609
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!opt_validate_config)
6610
8/16
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
18 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_BUILTIN_PLUGINS);
6611
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
18 unireg_abort(1);
6612 }
6613
6614 /*
6615 Needs to be done before dd::init() which runs DDL commands (for real)
6616 during instance initialization.
6617 */
6618
1/2
✓ Branch 0 taken 12036 times.
✗ Branch 1 not taken.
12036 init_sql_command_flags();
6619
6620 /*
6621 plugin_register_dynamic_and_init_all() needs DD initialized.
6622 Initialize DD to create data directory using current server.
6623 */
6624
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 11742 times.
12036 if (opt_initialize) {
6625
2/2
✓ Branch 0 taken 293 times.
✓ Branch 1 taken 1 times.
294 if (!is_help_or_validate_option()) {
6626
3/4
✓ Branch 0 taken 293 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 290 times.
293 if (dd::init(dd::enum_dd_init_type::DD_INITIALIZE)) {
6627
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_DD_INIT_FAILED);
6628
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
3 unireg_abort(1);
6629 }
6630
6631
2/4
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 290 times.
290 if (dd::init(dd::enum_dd_init_type::DD_INITIALIZE_SYSTEM_VIEWS)) {
6632 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
6633 unireg_abort(1);
6634 }
6635 }
6636 } else {
6637 /*
6638 Initialize DD in case of upgrade and normal normal server restart.
6639 It is detected if we are starting on old data directory or current
6640 data directory. If it is old data directory, DD tables are created.
6641 If server is starting on data directory with DD tables, DD is initialized.
6642 */
6643
4/4
✓ Branch 0 taken 11725 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 11629 times.
23465 if (!is_help_or_validate_option() &&
6644
3/4
✓ Branch 0 taken 11723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 11612 times.
11725 dd::init(dd::enum_dd_init_type::DD_RESTART_OR_UPGRADE)) {
6645
8/16
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 111 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 111 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 111 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 111 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 111 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 111 times.
✗ Branch 15 not taken.
111 LogErr(ERROR_LEVEL, ER_DD_INIT_FAILED);
6646
6647
3/4
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 107 times.
✓ Branch 3 taken 4 times.
111 if (!dd::upgrade::no_server_upgrade_required()) {
6648 107 dd_init_failed_during_upgrade = true;
6649 }
6650
6651 /* If clone recovery fails, we rollback the files to previous
6652 dataset and attempt to restart server. */
6653 111 int exit_code =
6654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 clone_recovery_error ? MYSQLD_RESTART_EXIT : MYSQLD_ABORT_EXIT;
6655
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
111 unireg_abort(exit_code);
6656 }
6657 }
6658
6659 /*
6660 During plugin initialization, a plugin may expect (depending on what the
6661 plugin actually does) to find a functional server, including:
6662 - mysql system tables
6663 - information schema tables
6664 - performance schema tables
6665 - data dictionary
6666 - components / services, including the registry service
6667 During the server installation, all these parts are not available yet, as
6668 they are created during the installation process with mysqld --initialize.
6669
6670 As a result, plugins are not loaded during mysqld --initialize, so that
6671 the server install can proceed and complete before any plugin is loaded
6672 through any config file or pre-programmed command line.
6673 */
6674 11920 int flags = 0;
6675
6676
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 11613 times.
11920 if (opt_noacl) flags |= PLUGIN_INIT_SKIP_PLUGIN_TABLE;
6677
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 11902 times.
11920 if (is_help_or_validate_option())
6678 18 flags |= PLUGIN_INIT_SKIP_INITIALIZATION | PLUGIN_INIT_SKIP_PLUGIN_TABLE;
6679
2/2
✓ Branch 0 taken 291 times.
✓ Branch 1 taken 11629 times.
11920 if (opt_initialize) flags |= PLUGIN_INIT_SKIP_DYNAMIC_LOADING;
6680
6681 /*
6682 In the case of upgrade, we need to delay initialization of plugins that
6683 depend on e.g. mysql tables that will be changed during upgrade.
6684 */
6685
2/2
✓ Branch 0 taken 11612 times.
✓ Branch 1 taken 290 times.
23822 if (!is_help_or_validate_option() && !opt_initialize &&
6686
7/8
✓ Branch 0 taken 11902 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11612 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 176 times.
✓ Branch 5 taken 11436 times.
✓ Branch 6 taken 173 times.
✓ Branch 7 taken 11747 times.
23998 !dd::upgrade::no_server_upgrade_required() &&
6687
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 3 times.
176 opt_upgrade_mode != UPGRADE_MINIMAL)
6688 173 flags |= PLUGIN_INIT_DELAY_UNTIL_AFTER_UPGRADE;
6689
6690 /*
6691 Initialize the cost model, but delete it after the plugins are initialized.
6692 Cost model is needed while dropping and creating pfs tables to
6693 update metadata of referencing views (if there are any).
6694 */
6695
1/2
✓ Branch 0 taken 11920 times.
✗ Branch 1 not taken.
11920 init_optimizer_cost_module(true);
6696 { // New scope in which the error handler hook is modified.
6697 11920 ErrorHandlerFunctionPointer ehh_val = error_handler_hook;
6698 23810 auto restore_ehh = create_scope_guard([ehh_val]() {
6699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11905 times.
11905 assert(ehh_val == my_message_stderr);
6700 11905 error_handler_hook = ehh_val;
6701
1/2
✓ Branch 0 taken 11920 times.
✗ Branch 1 not taken.
11920 });
6702 11920 error_handler_hook = +[](uint c, const char *s, myf f) {
6703
4/4
✓ Branch 0 taken 2655 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2648 times.
2657 if (c != ER_NO_SUCH_TABLE || strstr(s, "mysql.server_cost") == nullptr) {
6704 9 my_message_stderr(c, s, f);
6705 }
6706 2657 };
6707
3/4
✓ Branch 0 taken 11920 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 11905 times.
11920 if (plugin_register_dynamic_and_init_all(&remaining_argc, remaining_argv,
6708 flags)) {
6709
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 delete_optimizer_cost_module();
6710 // Delete all DD tables in case of error in initializing plugins.
6711
2/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
15 if (dd::upgrade_57::in_progress())
6712 (void)dd::init(dd::enum_dd_init_type::DD_DELETE);
6713
6714
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (!opt_validate_config)
6715
8/16
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 15 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 15 times.
✗ Branch 15 not taken.
15 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_DYNAMIC_PLUGINS);
6716
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
15 unireg_abort(MYSQLD_ABORT_EXIT);
6717 }
6718 11905 } // End of extra scope where missing server_cost errors are not logged
6719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11905 times.
11905 assert(error_handler_hook == my_message_stderr);
6720 11905 dynamic_plugins_are_initialized =
6721 true; /* Don't separate from init function */
6722
1/2
✓ Branch 0 taken 11905 times.
✗ Branch 1 not taken.
11905 delete_optimizer_cost_module();
6723
6724 11905 LEX_CSTRING plugin_name = {STRING_WITH_LEN("thread_pool")};
6725 23810 if (Connection_handler_manager::thread_handling !=
6726
4/4
✓ Branch 0 taken 11853 times.
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 11853 times.
23758 Connection_handler_manager::SCHEDULER_ONE_THREAD_PER_CONNECTION ||
6727
2/4
✓ Branch 0 taken 11853 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11853 times.
11853 plugin_is_ready(plugin_name, MYSQL_DAEMON_PLUGIN)) {
6728
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
6729
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 res_grp_mgr->disable_resource_group();
6730
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
52 res_grp_mgr->set_unsupport_reason("Thread pool plugin enabled");
6731 }
6732
6733 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
6734
2/2
✓ Branch 0 taken 11887 times.
✓ Branch 1 taken 18 times.
11905 if (!is_help_or_validate_option()) {
6735 /*
6736 Initialize the cost model, but delete it after the pfs is initialized.
6737 Cost model is needed while dropping and creating pfs tables to
6738 update metadata of referencing views (if there are any).
6739 */
6740
1/2
✓ Branch 0 taken 11887 times.
✗ Branch 1 not taken.
11887 init_optimizer_cost_module(true);
6741
6742 bool st;
6743
7/8
✓ Branch 0 taken 11597 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 11597 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11509 times.
✓ Branch 5 taken 88 times.
✓ Branch 6 taken 414 times.
✓ Branch 7 taken 11473 times.
23396 if (opt_initialize || dd::upgrade_57::in_progress() ||
6744
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 11473 times.
11509 opt_upgrade_mode == UPGRADE_FORCE)
6745
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 st = dd::performance_schema::init_pfs_tables(
6746 dd::enum_dd_init_type::DD_INITIALIZE);
6747 else
6748
1/2
✓ Branch 0 taken 11473 times.
✗ Branch 1 not taken.
11473 st = dd::performance_schema::init_pfs_tables(
6749 dd::enum_dd_init_type::DD_RESTART_OR_UPGRADE);
6750
6751 /* Now that the pfs is initialized, delete the cost model. */
6752
1/2
✓ Branch 0 taken 11887 times.
✗ Branch 1 not taken.
11887 delete_optimizer_cost_module();
6753
6754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11887 times.
11887 if (st) {
6755 LogErr(ERROR_LEVEL, ER_PERFSCHEMA_TABLES_INIT_FAILED);
6756 unireg_abort(1);
6757 }
6758 }
6759 #endif
6760
6761
7/8
✓ Branch 0 taken 11887 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11887 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88 times.
✓ Branch 5 taken 11799 times.
✓ Branch 6 taken 88 times.
✓ Branch 7 taken 11817 times.
11905 if (!is_help_or_validate_option() && dd::upgrade_57::in_progress()) {
6762 // Populate DD tables with meta data from 5.7
6763
3/4
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 72 times.
88 if (dd::init(dd::enum_dd_init_type::DD_POPULATE_UPGRADE)) {
6764
8/16
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 16 times.
✗ Branch 15 not taken.
16 LogErr(ERROR_LEVEL, ER_DD_POPULATING_TABLES_FAILED);
6765
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
16 unireg_abort(1);
6766 }
6767 // Run after_dd_upgrade hook
6768
3/8
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 72 times.
72 if (RUN_HOOK(server_state, after_dd_upgrade_from_57, (nullptr)))
6769 unireg_abort(MYSQLD_ABORT_EXIT);
6770 }
6771
6772 /*
6773 Store server and plugin IS tables metadata into new DD.
6774 This is done after all the plugins are registered.
6775 */
6776
2/2
✓ Branch 0 taken 11581 times.
✓ Branch 1 taken 290 times.
23760 if (!is_help_or_validate_option() && !opt_initialize &&
6777
5/8
✓ Branch 0 taken 11871 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11581 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11581 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 11889 times.
35341 !dd::upgrade_57::in_progress() &&
6778
2/4
✓ Branch 0 taken 11581 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11581 times.
11581 dd::init(dd::enum_dd_init_type::DD_UPDATE_I_S_METADATA)) {
6779 LogErr(ERROR_LEVEL, ER_DD_UPDATING_PLUGIN_MD_FAILED);
6780 unireg_abort(MYSQLD_ABORT_EXIT);
6781 }
6782
6783
1/2
✓ Branch 0 taken 11889 times.
✗ Branch 1 not taken.
11889 bool recreate_non_dd_based_system_view = dd::upgrade::I_S_upgrade_required();
6784
6/6
✓ Branch 0 taken 11871 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11581 times.
✓ Branch 3 taken 290 times.
✓ Branch 4 taken 160 times.
✓ Branch 5 taken 11729 times.
23470 if (!is_help_or_validate_option() && !opt_initialize &&
6785
3/4
✓ Branch 0 taken 11581 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 11421 times.
11581 !dd::upgrade::no_server_upgrade_required()) {
6786
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 157 times.
160 if (opt_upgrade_mode == UPGRADE_MINIMAL)
6787
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_SERVER_UPGRADE_SKIP);
6788 else {
6789
1/2
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
157 init_optimizer_cost_module(true);
6790
2/4
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
157 if (bootstrap::run_bootstrap_thread(nullptr, nullptr,
6791 &dd::upgrade::upgrade_system_schemas,
6792 SYSTEM_THREAD_SERVER_UPGRADE)) {
6793 LogErr(ERROR_LEVEL, ER_SERVER_UPGRADE_FAILED);
6794 unireg_abort(MYSQLD_ABORT_EXIT);
6795 }
6796
1/2
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
157 delete_optimizer_cost_module();
6797 157 recreate_non_dd_based_system_view = true;
6798
6799 /*
6800 When upgrade is finished, we need to initialize the plugins that
6801 had their initialization delayed due to dependencies on the
6802 environment.
6803
6804 TODO: Provide a better long term solution by re-ordering startup
6805 sequence and rewriting the way we create and upgrade server
6806 resources needed by plugins.
6807 */
6808
2/4
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
157 if (dd::upgrade::plugin_initialize_delayed_after_upgrade()) {
6809 unireg_abort(MYSQLD_ABORT_EXIT);
6810 }
6811 }
6812 }
6813
6814 /*
6815 Re-create non DD based system views after a) if we upgraded system
6816 schemas b) I_S system view version is changed and server system views
6817 were recreated. c) If the database was upgraded. We do not update this
6818 in upgrade-minimal mode.
6819 */
6820
2/2
✓ Branch 0 taken 11581 times.
✓ Branch 1 taken 290 times.
23760 if (!is_help_or_validate_option() && !opt_initialize &&
6821
8/8
✓ Branch 0 taken 11871 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11578 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 157 times.
✓ Branch 5 taken 11421 times.
✓ Branch 6 taken 157 times.
✓ Branch 7 taken 11732 times.
23760 opt_upgrade_mode != UPGRADE_MINIMAL &&
6822 recreate_non_dd_based_system_view) {
6823
2/4
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
157 if (dd::init(
6824 dd::enum_dd_init_type::DD_INITIALIZE_NON_DD_BASED_SYSTEM_VIEWS)) {
6825 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
6826 unireg_abort(MYSQLD_ABORT_EXIT);
6827 }
6828 }
6829
6830
1/2
✓ Branch 0 taken 11889 times.
✗ Branch 1 not taken.
11889 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
6831 // Initialize the Resource group subsystem.
6832
6/6
✓ Branch 0 taken 11871 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 11581 times.
✓ Branch 3 taken 290 times.
✓ Branch 4 taken 11581 times.
✓ Branch 5 taken 308 times.
11889 if (!is_help_or_validate_option() && !opt_initialize) {
6833
2/4
✓ Branch 0 taken 11581 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11581 times.
11581 if (res_grp_mgr->post_init()) {
6834 LogErr(ERROR_LEVEL, ER_RESOURCE_GROUP_POST_INIT_FAILED);
6835 unireg_abort(MYSQLD_ABORT_EXIT);
6836 }
6837 }
6838
6839 Session_tracker session_track_system_variables_check;
6840 LEX_STRING var_list;
6841 char *tmp_str;
6842 11889 size_t len = strlen(global_system_variables.track_sysvars_ptr);
6843
1/2
✓ Branch 0 taken 11889 times.
✗ Branch 1 not taken.
11889 tmp_str = (char *)my_malloc(PSI_NOT_INSTRUMENTED, len * sizeof(char) + 2,
6844 MYF(MY_WME));
6845 11889 strcpy(tmp_str, global_system_variables.track_sysvars_ptr);
6846 11889 var_list.length = len;
6847 11889 var_list.str = tmp_str;
6848
2/4
✓ Branch 0 taken 11889 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11889 times.
11889 if (session_track_system_variables_check.server_boot_verify(
6849 system_charset_info, var_list)) {
6850 LogErr(ERROR_LEVEL, ER_TRACK_VARIABLES_BOGUS);
6851 if (tmp_str) my_free(tmp_str);
6852 unireg_abort(MYSQLD_ABORT_EXIT);
6853 }
6854
2/4
✓ Branch 0 taken 11889 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11889 times.
✗ Branch 3 not taken.
11889 if (tmp_str) my_free(tmp_str);
6855
6856 // Validate the configuration if --validate-config was specified.
6857
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11884 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
11889 if (opt_validate_config && (remaining_argc > 1)) {
6858 5 bool saved_getopt_skip_unknown = my_getopt_skip_unknown;
6859 5 struct my_option no_opts[] = {{nullptr, 0, nullptr, nullptr, nullptr,
6860 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
6861 nullptr, 0, nullptr}};
6862
6863 5 my_getopt_skip_unknown = false;
6864
6865
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 if (handle_options(&remaining_argc, &remaining_argv, no_opts,
6866 mysqld_get_one_option))
6867
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
6868 3 my_getopt_skip_unknown = saved_getopt_skip_unknown;
6869 }
6870
6871
2/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 11871 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11887 if (is_help_or_validate_option()) unireg_abort(MYSQLD_SUCCESS_EXIT);
6872
6873 /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
6874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11871 times.
11871 if (!my_default_lc_messages->errmsgs->is_loaded()) {
6875 LogErr(ERROR_LEVEL, ER_CANT_READ_ERRMSGS);
6876 unireg_abort(MYSQLD_ABORT_EXIT);
6877 }
6878
6879
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11866 times.
11871 if (opt_libcoredumper) {
6880 #if HAVE_LIBCOREDUMPER
6881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (opt_corefile) {
6882 sql_print_warning(
6883 "Started with --core-file and --coredumper. "
6884 "--coredumper will take precedence.");
6885 }
6886
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (opt_libcoredumper_path != NULL) {
6887
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!validate_libcoredumper_path(opt_libcoredumper_path)) {
6888
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5 unireg_abort(MYSQLD_ABORT_EXIT);
6889 }
6890 }
6891 #else
6892 sql_print_warning(
6893 "This version of MySQL has not been compiled with "
6894 "libcoredumper support, ignoring --coredumper argument");
6895 #endif
6896 }
6897
6898 /* We have to initialize the storage engines before CSV logging */
6899
2/4
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11866 times.
11866 if (ha_init()) {
6900 LogErr(ERROR_LEVEL, ER_CANT_INIT_DBS);
6901 unireg_abort(MYSQLD_ABORT_EXIT);
6902 }
6903
6904 /* Initialize ndbinfo tables in DD */
6905
2/4
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11866 times.
11866 if (dd::ndbinfo::init_schema_and_tables(opt_upgrade_mode)) {
6906 LogErr(ERROR_LEVEL, ER_NDBINFO_UPGRADING_SCHEMA_FAIL);
6907 unireg_abort(1);
6908 }
6909
6910
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 11576 times.
11866 if (opt_initialize) log_output_options = LOG_FILE;
6911
6912 /*
6913 Issue a warning if there were specified additional options to the
6914 log-output along with NONE. Probably this wasn't what user wanted.
6915 */
6916
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11866 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11866 if ((log_output_options & LOG_NONE) && (log_output_options & ~LOG_NONE))
6917 LogErr(WARNING_LEVEL, ER_LOG_OUTPUT_CONTRADICTORY);
6918
6919
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11865 times.
11866 if (log_output_options & LOG_TABLE) {
6920 /* Fall back to log files if the csv engine is not loaded. */
6921 1 LEX_CSTRING csv_name = {STRING_WITH_LEN("csv")};
6922
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!plugin_is_ready(csv_name, MYSQL_STORAGE_ENGINE_PLUGIN)) {
6923 LogErr(ERROR_LEVEL, ER_NO_CSV_NO_LOG_TABLES);
6924 log_output_options = (log_output_options & ~LOG_TABLE) | LOG_FILE;
6925 }
6926 }
6927
6928
1/2
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
11866 query_logger.set_handlers(log_output_options);
6929
6930 // Open slow log file if enabled.
6931
1/2
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
11866 query_logger.set_log_file(QUERY_LOG_SLOW);
6932
7/8
✓ Branch 0 taken 11433 times.
✓ Branch 1 taken 433 times.
✓ Branch 2 taken 11433 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11432 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 11865 times.
11866 if (opt_slow_log && query_logger.reopen_log_file(QUERY_LOG_SLOW))
6933 1 opt_slow_log = false;
6934
6935 // Open general log file if enabled.
6936
1/2
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
11866 query_logger.set_log_file(QUERY_LOG_GENERAL);
6937
7/8
✓ Branch 0 taken 11433 times.
✓ Branch 1 taken 433 times.
✓ Branch 2 taken 11433 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11432 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 11865 times.
11866 if (opt_general_log && query_logger.reopen_log_file(QUERY_LOG_GENERAL))
6938 1 opt_general_log = false;
6939
6940 /*
6941 Set the default storage engines
6942 */
6943
2/4
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11866 times.
11866 if (initialize_storage_engine(default_storage_engine, "",
6944 &global_system_variables.table_plugin))
6945 unireg_abort(MYSQLD_ABORT_EXIT);
6946
2/4
✓ Branch 0 taken 11866 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11866 times.
11866 if (initialize_storage_engine(default_tmp_storage_engine, " temp",
6947 &global_system_variables.temp_table_plugin))
6948 unireg_abort(MYSQLD_ABORT_EXIT);
6949
6950
4/4
✓ Branch 0 taken 11576 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 11562 times.
✓ Branch 3 taken 14 times.
11866 if (!opt_initialize && !opt_noacl) {
6951
1/2
✓ Branch 0 taken 11562 times.
✗ Branch 1 not taken.
11562 set_externally_disabled_storage_engine_names(opt_disabled_storage_engines);
6952
6953 // Log warning if default_storage_engine is a disabled storage engine.
6954 handlerton *default_se_handle =
6955 11562 plugin_data<handlerton *>(global_system_variables.table_plugin);
6956
3/4
✓ Branch 0 taken 11562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 11558 times.
11562 if (ha_is_storage_engine_disabled(default_se_handle))
6957
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_DISABLED_STORAGE_ENGINE_AS_DEFAULT,
6958 "default_storage_engine", default_storage_engine);
6959
6960 // Log warning if default_tmp_storage_engine is a disabled storage engine.
6961 handlerton *default_tmp_se_handle =
6962 11562 plugin_data<handlerton *>(global_system_variables.temp_table_plugin);
6963
3/4
✓ Branch 0 taken 11562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 11558 times.
11562 if (ha_is_storage_engine_disabled(default_tmp_se_handle))
6964
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_DISABLED_STORAGE_ENGINE_AS_DEFAULT,
6965 "default_tmp_storage_engine", default_tmp_storage_engine);
6966 }
6967
6968 /*
6969 Validate any enforced storage engine
6970 */
6971
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11861 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
11866 if (enforce_storage_engine && !opt_initialize && !opt_noacl) {
6972 const LEX_CSTRING name{enforce_storage_engine,
6973 5 strlen(enforce_storage_engine)};
6974 plugin_ref plugin;
6975
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if ((plugin = ha_resolve_by_name(nullptr, &name, false))) {
6976 5 handlerton *hton = plugin_data<handlerton *>(plugin);
6977 const LEX_CSTRING defname{default_storage_engine,
6978 5 strlen(default_storage_engine)};
6979 plugin_ref defplugin;
6980 handlerton *defhton;
6981
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if ((defplugin = ha_resolve_by_name(nullptr, &defname, false))) {
6982 5 defhton = plugin_data<handlerton *>(defplugin);
6983
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (defhton != hton) {
6984
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 sql_print_warning(
6985 "Default storage engine (%s)"
6986 " is not the same as enforced storage engine (%s)",
6987 default_storage_engine, enforce_storage_engine);
6988 }
6989 }
6990
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
5 if (ha_is_storage_engine_disabled(hton)) {
6991
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
6992 "enforced storage engine %s is among disabled storage "
6993 "engines",
6994 enforce_storage_engine);
6995
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(MYSQLD_ABORT_EXIT);
6996 }
6997
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 plugin_unlock(nullptr, defplugin);
6998
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 plugin_unlock(nullptr, plugin);
6999 } else {
7000 sql_print_error("Unknown/unsupported storage engine: %s",
7001 enforce_storage_engine);
7002 unireg_abort(MYSQLD_ABORT_EXIT);
7003 }
7004 }
7005
7006
3/4
✓ Branch 0 taken 11865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11864 times.
11865 DBUG_EXECUTE_IF("total_ha_2pc_equals_2", total_ha_2pc = 2;);
7007
4/6
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 11325 times.
✓ Branch 2 taken 540 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 540 times.
11865 if (total_ha_2pc > 1 || (1 == total_ha_2pc && opt_bin_log)) {
7008
2/2
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 4 times.
11325 if (opt_bin_log)
7009 11321 tc_log = &mysql_bin_log;
7010 else
7011 4 tc_log = &tc_log_mmap;
7012 }
7013
7014
2/4
✓ Branch 0 taken 11865 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11865 times.
11865 if (Recovered_xa_transactions::init()) {
7015 LogErr(ERROR_LEVEL, ER_OOM);
7016 unireg_abort(MYSQLD_ABORT_EXIT);
7017 }
7018
7019
4/6
✓ Branch 0 taken 11865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1514 times.
✓ Branch 3 taken 10351 times.
✓ Branch 4 taken 1514 times.
✗ Branch 5 not taken.
11865 RUN_HOOK(server_state, before_recovery, (nullptr));
7020
5/6
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 544 times.
✓ Branch 2 taken 11865 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 11787 times.
11865 if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file)) {
7021
8/16
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 78 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 78 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 78 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 78 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 78 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 78 times.
✗ Branch 15 not taken.
78 LogErr(ERROR_LEVEL, ER_CANT_INIT_TC_LOG);
7022
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
78 unireg_abort(MYSQLD_ABORT_EXIT);
7023 }
7024
7025
2/4
✓ Branch 0 taken 11787 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11787 times.
11787 if (dd::reset_tables_and_tablespaces()) {
7026 unireg_abort(MYSQLD_ABORT_EXIT);
7027 }
7028
1/2
✓ Branch 0 taken 11785 times.
✗ Branch 1 not taken.
11787 ha_post_recover();
7029
7030 /*
7031 Add prepared XA transactions into the cache of XA transactions and acquire
7032 mdl lock for every table involved in any of these prepared XA transactions.
7033 This step moved away from the function ha_recover() in order to avoid
7034 possible suspending on acquiring EXCLUSIVE mdl lock on tables inside the
7035 function dd::reset_tables_and_tablespaces() when table cache being reset.
7036 */
7037
1/2
✓ Branch 0 taken 11785 times.
✗ Branch 1 not taken.
11785 if (Recovered_xa_transactions::instance()
7038
2/4
✓ Branch 0 taken 11785 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11785 times.
11785 .recover_prepared_xa_transactions()) {
7039 unireg_abort(MYSQLD_ABORT_EXIT);
7040 }
7041
7042
5/6
✓ Branch 0 taken 11785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2203 times.
✓ Branch 3 taken 9582 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 11782 times.
13988 if (global_gtid_mode.get() == Gtid_mode::ON &&
7043
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2200 times.
2203 _gtid_consistency_mode != GTID_CONSISTENCY_MODE_ON) {
7044
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_RPL_GTID_MODE_REQUIRES_ENFORCE_GTID_CONSISTENCY_ON);
7045
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
3 unireg_abort(MYSQLD_ABORT_EXIT);
7046 }
7047
7048
3/4
✓ Branch 0 taken 11782 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 11770 times.
11782 if (rpl_encryption.initialize()) {
7049
8/16
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
12 LogErr(ERROR_LEVEL, ER_SERVER_RPL_ENCRYPTION_UNABLE_TO_INITIALIZE);
7050
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
12 unireg_abort(MYSQLD_ABORT_EXIT);
7051 }
7052
7053
7/8
✓ Branch 0 taken 11770 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
✓ Branch 3 taken 11705 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 61 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 11766 times.
11770 if (rpl_encryption.is_enabled() && !opt_bin_log) {
7054
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 sql_print_information(
7055 "binlog and relay log encryption enabled without binary logging being "
7056 "enabled. "
7057 "If relay logs are in use, they will be encrypted.");
7058 }
7059
7060
2/2
✓ Branch 0 taken 11226 times.
✓ Branch 1 taken 544 times.
11770 if (opt_bin_log) {
7061 /*
7062 Configures what object is used by the current log to store processed
7063 gtid(s). This is necessary in the MYSQL_BIN_LOG::MYSQL_BIN_LOG to
7064 correctly compute the set of previous gtids.
7065 */
7066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11226 times.
11226 assert(!mysql_bin_log.is_relay_log);
7067 11226 mysql_mutex_t *log_lock = mysql_bin_log.get_log_lock();
7068
1/2
✓ Branch 0 taken 11226 times.
✗ Branch 1 not taken.
11226 mysql_mutex_lock(log_lock);
7069
7070
3/4
✓ Branch 0 taken 11226 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11224 times.
11226 if (mysql_bin_log.open_binlog(opt_bin_logname, nullptr, max_binlog_size,
7071 false, true /*need_lock_index=true*/,
7072 true /*need_sid_lock=true*/, nullptr)) {
7073
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mysql_mutex_unlock(log_lock);
7074
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
7075 }
7076
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 mysql_mutex_unlock(log_lock);
7077 }
7078
7079 /*
7080 When we pass non-zero values for both expire_logs_days and
7081 binlog_expire_logs_seconds at the server start-up, the value of
7082 expire_logs_days will be ignored and only binlog_expire_logs_seconds
7083 will be used.
7084 */
7085
4/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11746 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 8 times.
11768 if (binlog_expire_logs_seconds_supplied && expire_logs_days_supplied) {
7086
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 5 times.
14 if (binlog_expire_logs_seconds != 0 && expire_logs_days != 0) {
7087
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_EXPIRE_LOGS_DAYS_IGNORED);
7088 3 expire_logs_days = 0;
7089 }
7090
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 11746 times.
11754 } else if (expire_logs_days_supplied)
7091 8 binlog_expire_logs_seconds = 0;
7092
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 11761 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
11768 assert(expire_logs_days == 0 || binlog_expire_logs_seconds == 0);
7093
7094
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 11224 times.
11768 if (!opt_bin_log) {
7095
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 537 times.
544 if (binlog_expire_logs_seconds_supplied)
7096
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-expire-logs-seconds");
7097
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 538 times.
544 if (expire_logs_days_supplied)
7098
8/16
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
6 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--expire_logs_days");
7099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 544 times.
544 if (binlog_space_limit)
7100 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-space-limit");
7101 }
7102
7103
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11768 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11768 if (opt_myisam_log) (void)mi_log(1);
7104
7105 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
7106
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11768 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11768 times.
11768 if (locked_in_memory && !getuid()) {
7107 if (setreuid((uid_t)-1, 0) == -1) { // this should never happen
7108 LogErr(ERROR_LEVEL, ER_FAIL_SETREUID, strerror(errno));
7109 unireg_abort(MYSQLD_ABORT_EXIT);
7110 }
7111 if (mlockall(MCL_CURRENT)) {
7112 LogErr(WARNING_LEVEL, ER_FAILED_TO_LOCK_MEM,
7113 errno); /* purecov: inspected */
7114 locked_in_memory = false;
7115 }
7116 #ifndef _WIN32
7117 if (!user_info.IsVoid()) set_user(mysqld_user, user_info);
7118 #endif
7119 } else
7120 #endif
7121 11768 locked_in_memory = false;
7122
7123
2/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11768 times.
✗ Branch 3 not taken.
11768 rpl_acf_configuration_handler = new Rpl_acf_configuration_handler();
7124
2/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11768 times.
11768 if (rpl_acf_configuration_handler->init()) {
7125 unireg_abort(MYSQLD_ABORT_EXIT);
7126 }
7127
2/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11768 times.
✗ Branch 3 not taken.
11768 rpl_source_io_monitor = new Source_IO_monitor();
7128
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 udf_load_service.init();
7129
7130 /* Initialize the optimizer cost module */
7131
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_optimizer_cost_module(true);
7132
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 ft_init_stopwords();
7133
7134
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_max_user_conn();
7135
7136
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_global_user_stats();
7137
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_global_client_stats();
7138
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_global_thread_stats();
7139
7140 #if defined(MYSQL_ICU_DATADIR)
7141
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 init_icu_data_directory();
7142 #endif // MYSQL_ICU_DATADIR
7143
7144 11768 return 0;
7145 11768 }
7146
7147 #ifdef _WIN32
7148
7149 extern "C" void *handle_shutdown_and_restart(void *arg) {
7150 MSG msg;
7151 HANDLE event_handles[2];
7152 event_handles[0] = hEventShutdown;
7153 event_handles[1] = hEventRestart;
7154
7155 my_thread_init();
7156 /* This call should create the message queue for this thread. */
7157 PeekMessage(&msg, NULL, 1, 65534, PM_NOREMOVE);
7158 DWORD ret_code = WaitForMultipleObjects(
7159 2, static_cast<HANDLE *>(event_handles), FALSE, INFINITE);
7160
7161 if (ret_code == WAIT_OBJECT_0 || ret_code == WAIT_OBJECT_0 + 1) {
7162 if (ret_code == WAIT_OBJECT_0)
7163 LogErr(SYSTEM_LEVEL, ER_NORMAL_SERVER_SHUTDOWN, my_progname);
7164 else
7165 signal_hand_thr_exit_code = MYSQLD_RESTART_EXIT;
7166
7167 set_connection_events_loop_aborted(true);
7168 close_connections();
7169 my_thread_end();
7170 my_thread_exit(0);
7171 }
7172 return 0;
7173 }
7174
7175 static void create_shutdown_and_restart_thread() {
7176 DBUG_TRACE;
7177
7178 const char *errmsg;
7179 my_thread_attr_t thr_attr;
7180 SECURITY_ATTRIBUTES *shutdown_sec_attr;
7181
7182 my_security_attr_create(&shutdown_sec_attr, &errmsg, GENERIC_ALL,
7183 SYNCHRONIZE | EVENT_MODIFY_STATE);
7184
7185 if (!opt_no_monitor) {
7186 snprintf(shutdown_event_name, sizeof(shutdown_event_name),
7187 "mysqld%s_shutdown", get_monitor_pid());
7188 }
7189
7190 hEventShutdown =
7191 CreateEvent(shutdown_sec_attr, FALSE, FALSE, shutdown_event_name);
7192 hEventRestart = CreateEvent(0, FALSE, FALSE, restart_event_name);
7193
7194 my_thread_attr_init(&thr_attr);
7195
7196 if (my_thread_create(&shutdown_restart_thr_handle, &thr_attr,
7197 handle_shutdown_and_restart, 0))
7198 LogErr(WARNING_LEVEL, ER_CANT_CREATE_SHUTDOWN_THREAD, errno);
7199
7200 my_security_attr_free(shutdown_sec_attr);
7201 my_thread_attr_destroy(&thr_attr);
7202 }
7203 #endif /* _WIN32 */
7204
7205 #ifndef NDEBUG
7206 /*
7207 Debugging helper function to keep the locale database
7208 (see sql_locale.cc) and max_month_name_length and
7209 max_day_name_length variable values in consistent state.
7210 */
7211 12069 static void test_lc_time_sz() {
7212
1/2
✓ Branch 0 taken 12069 times.
✗ Branch 1 not taken.
12069 DBUG_TRACE;
7213
2/2
✓ Branch 0 taken 1339659 times.
✓ Branch 1 taken 12069 times.
1351728 for (MY_LOCALE **loc = my_locales; *loc; loc++) {
7214 1339659 size_t max_month_len = 0;
7215 1339659 size_t max_day_len = 0;
7216
2/2
✓ Branch 0 taken 16075908 times.
✓ Branch 1 taken 1339659 times.
17415567 for (const char **month = (*loc)->month_names->type_names; *month;
7217 month++) {
7218 32151816 max_month_len = std::max(
7219 16075908 max_month_len, my_numchars_mb(&my_charset_utf8_general_ci, *month,
7220
1/2
✓ Branch 0 taken 16075908 times.
✗ Branch 1 not taken.
16075908 *month + strlen(*month)));
7221 }
7222
2/2
✓ Branch 0 taken 9377613 times.
✓ Branch 1 taken 1339659 times.
10717272 for (const char **day = (*loc)->day_names->type_names; *day; day++) {
7223 9377613 max_day_len =
7224 9377613 std::max(max_day_len, my_numchars_mb(&my_charset_utf8_general_ci,
7225
1/2
✓ Branch 0 taken 9377613 times.
✗ Branch 1 not taken.
9377613 *day, *day + strlen(*day)));
7226 }
7227
1/2
✓ Branch 0 taken 1339659 times.
✗ Branch 1 not taken.
1339659 if ((*loc)->max_month_name_length != max_month_len ||
7228
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1339659 times.
1339659 (*loc)->max_day_name_length != max_day_len) {
7229 DBUG_PRINT("Wrong max day name(or month name) length for locale:",
7230 ("%s", (*loc)->name));
7231 assert(0);
7232 }
7233 }
7234 12069 }
7235 #endif // NDEBUG
7236
7237 /*
7238 @brief : Set opt_super_readonly to user supplied value before
7239 enabling communication channels to accept user connections
7240 */
7241
7242 11401 static void set_super_read_only_post_init() {
7243 11401 opt_super_readonly = super_read_only;
7244 11401 }
7245
7246 12121 static void calculate_mysql_home_from_my_progname() {
7247 const std::string runtime_output_directory_addon{
7248
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 "/runtime_output_directory/"};
7249 #if defined(_WIN32) || defined(APPLE_XCODE)
7250 /* Allow Win32 users to move MySQL anywhere */
7251 char prg_dev[FN_REFLEN];
7252 my_path(prg_dev, my_progname, nullptr);
7253
7254 // On windows or Xcode the basedir will always be one level up from where
7255 // the executable is located. E.g. <basedir>/bin/mysqld.exe in a
7256 // package, or <basedir>/runtime_output_directory/<buildconfig>/mysqld.exe
7257 // for a sandbox build.
7258 strcat(prg_dev, "/../"); // Remove containing directory to get base dir
7259 cleanup_dirname(mysql_home, prg_dev);
7260
7261 // New layout: <cmake_binary_dir>/runtime_output_directory/<buildconfig>/
7262 char cmake_binary_dir[FN_REFLEN];
7263 size_t dlen = 0;
7264 dirname_part(cmake_binary_dir, mysql_home, &dlen);
7265 if (dlen > runtime_output_directory_addon.length() &&
7266 (!strcmp(
7267 cmake_binary_dir + (dlen - runtime_output_directory_addon.length()),
7268 runtime_output_directory_addon.c_str()) ||
7269 !strcmp(
7270 cmake_binary_dir + (dlen - runtime_output_directory_addon.length()),
7271 "\\runtime_output_directory\\"))) {
7272 mysql_home[strlen(mysql_home) - 1] = '\0'; // remove trailing
7273 dirname_part(cmake_binary_dir, mysql_home, &dlen);
7274 strmake(mysql_home, cmake_binary_dir, sizeof(mysql_home) - 1);
7275 }
7276 // The sql_print_information below outputs nothing ??
7277 // fprintf(stderr, "mysql_home %s\n", mysql_home);
7278 // fflush(stderr);
7279 #else
7280 12121 const char *tmpenv = getenv("MY_BASEDIR_VERSION");
7281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12121 times.
12121 if (tmpenv != nullptr) {
7282 strmake(mysql_home, tmpenv, sizeof(mysql_home) - 1);
7283 } else {
7284 char progdir[FN_REFLEN];
7285 12121 size_t dlen = 0;
7286
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 dirname_part(progdir, my_progname, &dlen);
7287
3/4
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12120 times.
✓ Branch 3 taken 1 times.
24242 if (dlen > runtime_output_directory_addon.length() &&
7288
2/2
✓ Branch 0 taken 12120 times.
✓ Branch 1 taken 1 times.
12121 !strcmp(progdir + (dlen - runtime_output_directory_addon.length()),
7289 runtime_output_directory_addon.c_str())) {
7290 char cmake_binary_dir[FN_REFLEN];
7291 12120 progdir[strlen(progdir) - 1] = '\0'; // remove trailing "/"
7292
1/2
✓ Branch 0 taken 12120 times.
✗ Branch 1 not taken.
12120 dirname_part(cmake_binary_dir, progdir, &dlen);
7293
1/2
✓ Branch 0 taken 12120 times.
✗ Branch 1 not taken.
12120 strmake(mysql_home, cmake_binary_dir, sizeof(mysql_home) - 1);
7294 } else {
7295 1 strcat(progdir, "/../");
7296
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cleanup_dirname(mysql_home, progdir);
7297 }
7298 }
7299 #endif
7300 12121 mysql_home_ptr = mysql_home;
7301 12121 }
7302
7303 /**
7304 Helper class for loading keyring component
7305 Keyring component is loaded after minimal chassis initialization.
7306 At this time, home dir and plugin dir may not be initialized.
7307
7308 This helper class sets them temporarily by reading configurations
7309 and resets them in destructor.
7310 */
7311 class Plugin_and_data_dir_option_parser final {
7312 public:
7313 12109 Plugin_and_data_dir_option_parser(int argc, char **argv)
7314 12109 : datadir_(nullptr),
7315 12109 plugindir_(nullptr),
7316 12109 save_homedir_{0},
7317 12109 save_plugindir_{0},
7318 12109 valid_(false) {
7319 12109 char *ptr, **res, *datadir = nullptr, *plugindir = nullptr;
7320 12109 char dir[FN_REFLEN] = {0}, local_datadir_buffer[FN_REFLEN] = {0},
7321 12109 local_plugindir_buffer[FN_REFLEN] = {0};
7322 12109 const char *dirs = nullptr;
7323
7324 12109 my_option datadir_options[] = {
7325 {"datadir", 0, "", &datadir, nullptr, nullptr, GET_STR, OPT_ARG, 0, 0,
7326 0, nullptr, 0, nullptr},
7327 {"plugin_dir", 0, "", &plugindir, nullptr, nullptr, GET_STR, OPT_ARG, 0,
7328 0, 0, nullptr, 0, nullptr},
7329 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0,
7330 12109 0, 0, nullptr, 0, nullptr}};
7331
7332 /*
7333 create temporary args list and pass it to handle_options.
7334 We do this because we don't want to mess with the actual
7335 argument list. handle_options() trims the processed parts.
7336 */
7337 12109 MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
7338 12109 if (!(ptr =
7339
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 (char *)alloc.Alloc(sizeof(alloc) + (argc + 1) * sizeof(char *))))
7340 return;
7341 12109 memset(ptr, 0, (sizeof(char *) * (argc + 1)));
7342 12109 res = (char **)(ptr);
7343 12109 memcpy((uchar *)res, (char *)(argv), (argc) * sizeof(char *));
7344
7345 12109 my_getopt_skip_unknown = true;
7346
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 if (my_handle_options(&argc, &res, datadir_options, nullptr, nullptr,
7347 true)) {
7348 my_getopt_skip_unknown = false;
7349 return;
7350 }
7351 12109 my_getopt_skip_unknown = false;
7352
7353
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 12082 times.
12109 if (!datadir) {
7354 /* mysql_real_data_home must be initialized at this point */
7355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 assert(mysql_real_data_home[0]);
7356 /*
7357 mysql_home_ptr should also be initialized at this point.
7358 See calculate_mysql_home_from_my_progname() for details
7359 */
7360
2/4
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
27 assert(mysql_home_ptr && mysql_home_ptr[0]);
7361
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 convert_dirname(local_datadir_buffer, mysql_real_data_home, NullS);
7362
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 (void)my_load_path(local_datadir_buffer, local_datadir_buffer,
7363 mysql_home_ptr);
7364 27 datadir = local_datadir_buffer;
7365 }
7366 12109 dirs = datadir;
7367
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 unpack_dirname(dir, dirs);
7368
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 datadir_ = my_strdup(PSI_INSTRUMENT_ME, dir, MYF(0));
7369 12109 memset(dir, 0, FN_REFLEN);
7370
7371
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 convert_dirname(local_plugindir_buffer,
7372
3/4
✓ Branch 0 taken 6067 times.
✓ Branch 1 taken 6042 times.
✓ Branch 2 taken 6067 times.
✗ Branch 3 not taken.
12109 plugindir ? plugindir : get_relative_path(PLUGINDIR),
7373 NullS);
7374
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 (void)my_load_path(local_plugindir_buffer, local_plugindir_buffer,
7375 mysql_home);
7376
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 plugindir_ = my_strdup(PSI_INSTRUMENT_ME, local_plugindir_buffer, MYF(0));
7377
7378 /* Backup mysql_real_data_home */
7379
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (mysql_real_data_home[0])
7380 12109 memcpy(save_homedir_, mysql_real_data_home, strlen(mysql_real_data_home));
7381
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (datadir_ != nullptr)
7382 12109 memcpy(mysql_real_data_home, datadir_, strlen(datadir_));
7383
7384 /* Backup opt_plugin_dir */
7385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 if (opt_plugin_dir[0])
7386 memcpy(save_plugindir_, opt_plugin_dir,
7387 std::min(static_cast<size_t>(FN_REFLEN), strlen(opt_plugin_dir)));
7388
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (plugindir_ != nullptr)
7389 12109 memcpy(opt_plugin_dir, plugindir_, strlen(plugindir_));
7390
7391 12109 valid_ = true;
7392
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 }
7393
7394 12109 ~Plugin_and_data_dir_option_parser() {
7395 12109 valid_ = false;
7396
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (datadir_ != nullptr) {
7397 12109 memset(mysql_real_data_home, 0, sizeof(mysql_real_data_home));
7398 12109 memcpy(mysql_real_data_home, save_homedir_, strlen(save_homedir_));
7399 12109 my_free(datadir_);
7400 }
7401
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (plugindir_ != nullptr) {
7402 12109 memset(opt_plugin_dir, 0, sizeof(opt_plugin_dir));
7403 12109 memcpy(opt_plugin_dir, save_plugindir_, strlen(save_plugindir_));
7404 12109 my_free(plugindir_);
7405 }
7406 12109 }
7407
7408 12109 bool valid() const { return valid_; }
7409
7410 private:
7411 char *datadir_;
7412 char *plugindir_;
7413 char save_homedir_[FN_REFLEN + 1];
7414 char save_plugindir_[FN_REFLEN + 1];
7415 bool valid_;
7416 };
7417
7418 #ifdef _WIN32
7419 int win_main(int argc, char **argv)
7420 #else
7421 12121 int mysqld_main(int argc, char **argv)
7422 #endif
7423 {
7424 // Substitute the full path to the executable in argv[0]
7425
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 substitute_progpath(argv);
7426
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 sysd::notify_connect();
7427
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 sysd::notify("STATUS=Server startup in progress\n");
7428
7429 /*
7430 Perform basic thread library and malloc initialization,
7431 to be able to read defaults files and parse options.
7432 */
7433 12121 my_progname = argv[0];
7434
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 calculate_mysql_home_from_my_progname();
7435
7436 #ifndef _WIN32
7437 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
7438
1/2
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
12121 pre_initialize_performance_schema();
7439 #endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
7440 // For windows, my_init() is called from the win specific mysqld_main
7441
2/4
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12121 times.
12121 if (my_init()) // init my_sys library & pthreads
7442 {
7443 LogErr(ERROR_LEVEL, ER_MYINIT_FAILED);
7444 flush_error_log_messages();
7445 return 1;
7446 }
7447 #endif /* _WIN32 */
7448
7449 12121 orig_argc = argc;
7450 12121 orig_argv = argv;
7451 12121 my_getopt_use_args_separator = true;
7452 12121 my_defaults_read_login_file = false;
7453
3/4
✓ Branch 0 taken 12121 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 12115 times.
12121 if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv,
7454 &argv_alloc)) {
7455
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 flush_error_log_messages();
7456 6 return 1;
7457 }
7458
7459 /* Set data dir directory paths */
7460
2/4
✓ Branch 0 taken 12115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12115 times.
✗ Branch 3 not taken.
12115 strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
7461 sizeof(mysql_real_data_home) - 1);
7462
7463 /* Must be initialized early for comparison of options name */
7464 12115 system_charset_info = &my_charset_utf8_general_ci;
7465
7466 /* Write mysys error messages to the error log. */
7467 12115 local_message_hook = error_log_print;
7468
7469
1/2
✓ Branch 0 taken 12115 times.
✗ Branch 1 not taken.
12115 sys_var_init();
7470
7471 #ifdef _WIN32
7472 if (mysys::is_my_malloc_using_jemalloc()) {
7473 LogErr(INFORMATION_LEVEL, ER_MY_MALLOC_USING_JEMALLOC);
7474 } else {
7475 for (auto &msg : mysys::fetch_jemalloc_initialization_messages()) {
7476 LogErr(msg.m_severity, ER_MY_MALLOC_USING_JEMALLOC + msg.m_ecode,
7477 msg.m_message.c_str());
7478 }
7479 }
7480 #endif
7481 /*
7482 Initialize variables cache for persisted variables, load persisted
7483 config file and append parse early read only persisted variables
7484 to command line options if present.
7485 */
7486 12115 bool arg_separator_added = false;
7487
1/2
✓ Branch 0 taken 12115 times.
✗ Branch 1 not taken.
12115 if (persisted_variables_cache.init(&argc, &argv) ||
7488
6/8
✓ Branch 0 taken 12115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12115 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12109 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 12109 times.
24224 persisted_variables_cache.load_persist_file() ||
7489
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 persisted_variables_cache.append_parse_early_variables(
7490 &argc, &argv, arg_separator_added)) {
7491
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 flush_error_log_messages();
7492 6 return 1;
7493 }
7494
7495 12109 remaining_argc = argc;
7496 12109 remaining_argv = argv;
7497
7498
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 init_variable_default_paths();
7499
7500 int heo_error;
7501
7502 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
7503 /*
7504 Initialize the array of performance schema instrument configurations.
7505 */
7506
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 init_pfs_instrument_array();
7507 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
7508
7509 /* init_error_log() is required by error_log_printf() in
7510 option_error_reporter() */
7511 // Init error log subsystem. This does not actually open the log yet.
7512
2/6
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12109 if (init_error_log()) unireg_abort(MYSQLD_ABORT_EXIT);
7513
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 heo_error = handle_early_options();
7514
7515
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 opt_jemalloc_detected = jemalloc_detected();
7516
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 jemalloc_profiling_enable(opt_jemalloc_profiling_enabled);
7517
7518 12109 init_sql_statement_names();
7519 12109 ulong requested_open_files = 0;
7520
3/4
✓ Branch 0 taken 12104 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 12104 times.
✗ Branch 3 not taken.
12109 if (!opt_validate_config) adjust_related_options(&requested_open_files);
7521 // moved signal initialization here so that PFS thread inherited signal mask
7522
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 my_init_signals();
7523
7524 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
7525
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (heo_error == 0) {
7526
6/6
✓ Branch 0 taken 12090 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 11790 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 11790 times.
✓ Branch 5 taken 319 times.
12109 if (!is_help_or_validate_option() && !opt_initialize) {
7527 int pfs_rc;
7528 /* Add sizing hints from the server sizing parameters. */
7529 11790 pfs_param.m_hints.m_table_definition_cache = table_def_size;
7530 11790 pfs_param.m_hints.m_table_open_cache = table_cache_size;
7531 11790 pfs_param.m_hints.m_max_connections = max_connections;
7532 11790 pfs_param.m_hints.m_open_files_limit = requested_open_files;
7533 11790 pfs_param.m_hints.m_max_prepared_stmt_count = max_prepared_stmt_count;
7534
7535
1/2
✓ Branch 0 taken 11790 times.
✗ Branch 1 not taken.
11790 pfs_rc = initialize_performance_schema(
7536 &pfs_param, &psi_thread_hook, &psi_mutex_hook, &psi_rwlock_hook,
7537 &psi_cond_hook, &psi_file_hook, &psi_socket_hook, &psi_table_hook,
7538 &psi_mdl_hook, &psi_idle_hook, &psi_stage_hook, &psi_statement_hook,
7539 &psi_transaction_hook, &psi_memory_hook, &psi_error_hook,
7540 &psi_data_lock_hook, &psi_system_hook, &psi_tls_channel_hook);
7541
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11790 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11790 if ((pfs_rc != 0) && pfs_param.m_enabled) {
7542 pfs_param.m_enabled = false;
7543 LogErr(WARNING_LEVEL, ER_PERFSCHEMA_INIT_FAILED);
7544 }
7545 }
7546 }
7547 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
7548
7549 #ifdef WITH_LOCK_ORDER
7550 if (heo_error == 0) {
7551 if (lo_param.m_enabled && !opt_help && !opt_initialize) {
7552 int lo_rc;
7553 lo_rc = LO_init(&lo_param, &psi_thread_hook, &psi_mutex_hook,
7554 &psi_rwlock_hook, &psi_cond_hook, &psi_file_hook,
7555 &psi_socket_hook, &psi_table_hook, &psi_mdl_hook,
7556 &psi_idle_hook, &psi_stage_hook, &psi_statement_hook,
7557 &psi_transaction_hook, &psi_memory_hook);
7558 if (lo_rc != 0) {
7559 LogErr(WARNING_LEVEL, ER_LOCK_ORDER_INIT_FAILED);
7560 }
7561 }
7562 }
7563 #endif /* WITH_LOCK_ORDER */
7564
7565 /*
7566 Other provider of the instrumentation interface should
7567 initialize PSI_hook here:
7568 - HAVE_PSI_INTERFACE is for the instrumentation interface
7569 - WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation
7570 of the interface,
7571 but there could be alternate implementations, which is why
7572 these two defines are kept separate.
7573 */
7574
7575 #ifdef HAVE_PSI_INTERFACE
7576 /*
7577 Obtain the current performance schema instrumentation interface,
7578 if available.
7579 */
7580
7581 void *service;
7582
7583
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_thread_hook != nullptr) {
7584
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_thread_hook->get_interface(PSI_CURRENT_THREAD_VERSION);
7585
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7586
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_thread_service(service);
7587 }
7588 }
7589
7590
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_mutex_hook != nullptr) {
7591
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_mutex_hook->get_interface(PSI_CURRENT_MUTEX_VERSION);
7592
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7593
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_mutex_service(service);
7594 }
7595 }
7596
7597
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_rwlock_hook != nullptr) {
7598
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_rwlock_hook->get_interface(PSI_CURRENT_RWLOCK_VERSION);
7599
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7600
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_rwlock_service(service);
7601 }
7602 }
7603
7604
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_cond_hook != nullptr) {
7605
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_cond_hook->get_interface(PSI_CURRENT_COND_VERSION);
7606
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7607
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_cond_service(service);
7608 }
7609 }
7610
7611
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_file_hook != nullptr) {
7612
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_file_hook->get_interface(PSI_CURRENT_FILE_VERSION);
7613
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7614
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_file_service(service);
7615 }
7616 }
7617
7618
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_socket_hook != nullptr) {
7619
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_socket_hook->get_interface(PSI_CURRENT_SOCKET_VERSION);
7620
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7621
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_socket_service(service);
7622 }
7623 }
7624
7625
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_table_hook != nullptr) {
7626
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_table_hook->get_interface(PSI_CURRENT_TABLE_VERSION);
7627
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7628
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_table_service(service);
7629 }
7630 }
7631
7632
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_mdl_hook != nullptr) {
7633
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_mdl_hook->get_interface(PSI_CURRENT_MDL_VERSION);
7634
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7635
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_mdl_service(service);
7636 }
7637 }
7638
7639
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_idle_hook != nullptr) {
7640
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_idle_hook->get_interface(PSI_CURRENT_IDLE_VERSION);
7641
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7642
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_idle_service(service);
7643 }
7644 }
7645
7646
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_stage_hook != nullptr) {
7647
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_stage_hook->get_interface(PSI_CURRENT_STAGE_VERSION);
7648
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7649
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_stage_service(service);
7650 }
7651 }
7652
7653
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_statement_hook != nullptr) {
7654
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_statement_hook->get_interface(PSI_CURRENT_STATEMENT_VERSION);
7655
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7656
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_statement_service(service);
7657 }
7658 }
7659
7660
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_transaction_hook != nullptr) {
7661 service =
7662
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 psi_transaction_hook->get_interface(PSI_CURRENT_TRANSACTION_VERSION);
7663
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7664
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_transaction_service(service);
7665 }
7666 }
7667
7668
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_memory_hook != nullptr) {
7669
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_memory_hook->get_interface(PSI_CURRENT_MEMORY_VERSION);
7670
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7671
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_memory_service(service);
7672 }
7673 }
7674
7675
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_error_hook != nullptr) {
7676
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_error_hook->get_interface(PSI_CURRENT_ERROR_VERSION);
7677
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7678
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_error_service(service);
7679 }
7680 }
7681
7682
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_data_lock_hook != nullptr) {
7683
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_data_lock_hook->get_interface(PSI_CURRENT_DATA_LOCK_VERSION);
7684
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7685
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_data_lock_service(service);
7686 }
7687 }
7688
7689
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_system_hook != nullptr) {
7690
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 service = psi_system_hook->get_interface(PSI_CURRENT_SYSTEM_VERSION);
7691
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7692
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_system_service(service);
7693 }
7694 }
7695
7696
2/2
✓ Branch 0 taken 11783 times.
✓ Branch 1 taken 326 times.
12109 if (psi_tls_channel_hook != nullptr) {
7697 service =
7698
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 psi_tls_channel_hook->get_interface(PSI_CURRENT_TLS_CHANNEL_VERSION);
7699
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 if (service != nullptr) {
7700
1/2
✓ Branch 0 taken 11783 times.
✗ Branch 1 not taken.
11783 set_psi_tls_channel_service(service);
7701 }
7702 }
7703
7704 /*
7705 Now that we have parsed the command line arguments, and have initialized
7706 the performance schema itself, the next step is to register all the
7707 server instruments.
7708 */
7709
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 init_server_psi_keys();
7710
7711 /*
7712 Now that some instrumentation is in place,
7713 recreate objects which were initialised early,
7714 so that they are instrumented as well.
7715 */
7716
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 my_thread_global_reinit();
7717 #endif /* HAVE_PSI_INTERFACE */
7718
7719 /* This limits ability to configure SSL library through config options */
7720
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 init_ssl();
7721
7722 /* Set umask as early as possible */
7723 12109 umask(((~my_umask) & 0666));
7724
7725 /*
7726 Initialize Components core subsystem early on, once we have PSI, which it
7727 uses. This part doesn't use any more MySQL-specific functionalities but
7728 error logging and PFS.
7729 */
7730
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 if (component_infrastructure_init()) {
7731 flush_error_log_messages();
7732 return 1;
7733 }
7734
7735 {
7736 /* Must be initialized early because it is required by dynamic loader */
7737 12109 files_charset_info = &my_charset_utf8_general_ci;
7738 auto keyring_helper = std::make_unique<Plugin_and_data_dir_option_parser>(
7739
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 remaining_argc, remaining_argv);
7740
7741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 if (keyring_helper->valid() == false) {
7742 flush_error_log_messages();
7743 return 1;
7744 }
7745
7746
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 if (initialize_manifest_file_components()) {
7747 flush_error_log_messages();
7748 return 1;
7749 }
7750
7751 /*
7752 If keyring component was loaded through manifest file, services provided
7753 by such a component should get priority over keyring plugin. That's why
7754 we have to set defaults before proxy keyring services are loaded.
7755 */
7756
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 set_srv_keyring_implementation_as_default();
7757
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 }
7758
7759 /*
7760 Append read only persisted variables to command line now.
7761 Note that if arg separator is already added, it will not
7762 be added again.
7763 */
7764
2/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12109 times.
12109 if (persisted_variables_cache.append_read_only_variables(
7765 &remaining_argc, &remaining_argv, arg_separator_added, false)) {
7766 flush_error_log_messages();
7767 return 1;
7768 }
7769 12109 my_getopt_use_args_separator = false;
7770
7771 /*
7772 Initialize Performance Schema component services.
7773 */
7774 #ifdef HAVE_PSI_THREAD_INTERFACE
7775
6/6
✓ Branch 0 taken 12090 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 11790 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 11790 times.
✓ Branch 5 taken 319 times.
12109 if (!is_help_or_validate_option() && !opt_initialize) {
7776
1/2
✓ Branch 0 taken 11790 times.
✗ Branch 1 not taken.
11790 register_pfs_notification_service();
7777
1/2
✓ Branch 0 taken 11790 times.
✗ Branch 1 not taken.
11790 register_pfs_resource_group_service();
7778 }
7779 #endif
7780
7781 // Initialize the resource group subsystem.
7782
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
7783
6/6
✓ Branch 0 taken 12090 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 11790 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 11790 times.
✓ Branch 5 taken 319 times.
12109 if (!is_help_or_validate_option() && !opt_initialize) {
7784
2/4
✓ Branch 0 taken 11790 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11790 times.
11790 if (res_grp_mgr->init()) {
7785 LogErr(ERROR_LEVEL, ER_RESOURCE_GROUP_SUBSYSTEM_INIT_FAILED);
7786 unireg_abort(MYSQLD_ABORT_EXIT);
7787 }
7788 }
7789
7790 #ifdef HAVE_PSI_THREAD_INTERFACE
7791 /* Instrument the main thread */
7792
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 PSI_thread *psi = PSI_THREAD_CALL(new_thread)(key_thread_main, 0, nullptr, 0);
7793
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 PSI_THREAD_CALL(set_thread_os_id)(psi);
7794
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 PSI_THREAD_CALL(set_thread)(psi);
7795 #endif /* HAVE_PSI_THREAD_INTERFACE */
7796
7797 /* Initialize audit interface globals. Audit plugins are inited later. */
7798
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 mysql_audit_initialize();
7799
7800
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 Srv_session::module_init();
7801
7802 /*
7803 Perform basic query log initialization. Should be called after
7804 MY_INIT, as it initializes mutexes.
7805 */
7806
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 query_logger.init();
7807
7808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 if (heo_error) {
7809 /*
7810 Parsing command line option failed,
7811 Since we don't have a workable remaining_argc/remaining_argv
7812 to continue the server initialization, this is as far as this
7813 code can go.
7814 This is the best effort to log meaningful messages:
7815 - messages will be printed to stderr, which is not redirected yet,
7816 - messages will be printed in the NT event log, for windows.
7817 */
7818 flush_error_log_messages();
7819 /*
7820 Not enough initializations for unireg_abort()
7821 Using exit() for windows.
7822 */
7823 exit(MYSQLD_ABORT_EXIT);
7824 }
7825
7826
3/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 12069 times.
12109 if (init_common_variables()) {
7827
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 setup_error_log();
7828
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
40 unireg_abort(MYSQLD_ABORT_EXIT); // Will do exit
7829 }
7830
7831
1/2
✓ Branch 0 taken 12069 times.
✗ Branch 1 not taken.
12069 keyring_lockable_init();
7832
7833 /*
7834 Install server's my_abort routine to assure my_aborts prints signal info
7835 sequentially without sudden termination.
7836 */
7837
1/2
✓ Branch 0 taken 12069 times.
✗ Branch 1 not taken.
12069 set_my_abort(my_server_abort);
7838
7839 12069 size_t guardize = 0;
7840 #ifndef _WIN32
7841 12069 int retval = pthread_attr_getguardsize(&connection_attrib, &guardize);
7842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12069 times.
12069 assert(retval == 0);
7843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12069 times.
12069 if (retval != 0) guardize = my_thread_stack_size;
7844 #endif
7845
7846 #if defined(__ia64__) || defined(__ia64)
7847 /*
7848 Peculiar things with ia64 platforms - it seems we only have half the
7849 stack size in reality, so we have to double it here
7850 */
7851 guardize = my_thread_stack_size;
7852 #endif
7853
7854
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12069 times.
12069 if (0 != my_thread_attr_setstacksize(&connection_attrib,
7855 my_thread_stack_size + guardize)) {
7856 assert(false);
7857 }
7858
7859 {
7860 /* Retrieve used stack size; Needed for checking stack overflows */
7861 12069 size_t stack_size = 0;
7862 12069 my_thread_attr_getstacksize(&connection_attrib, &stack_size);
7863
7864 /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
7865
2/4
✓ Branch 0 taken 12069 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12069 times.
12069 if (stack_size && stack_size < (my_thread_stack_size + guardize)) {
7866 LogErr(WARNING_LEVEL, ER_STACKSIZE_UNEXPECTED,
7867 my_thread_stack_size + guardize, (long)stack_size);
7868 #if defined(__ia64__) || defined(__ia64)
7869 my_thread_stack_size = stack_size / 2;
7870 #else
7871 my_thread_stack_size = static_cast<ulong>(stack_size - guardize);
7872 #endif
7873 }
7874 }
7875
7876 #ifndef NDEBUG
7877
1/2
✓ Branch 0 taken 12069 times.
✗ Branch 1 not taken.
12069 test_lc_time_sz();
7878 12069 srand(static_cast<uint>(time(nullptr)));
7879 #endif
7880
7881 #if !defined(_WIN32)
7882
7883
3/4
✓ Branch 0 taken 298 times.
✓ Branch 1 taken 11771 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 298 times.
12069 if (opt_initialize && opt_daemonize) {
7884 fprintf(stderr, "Initialize and daemon options are incompatible.\n");
7885 unireg_abort(MYSQLD_ABORT_EXIT);
7886 }
7887
7888
6/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12063 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12069 times.
12073 if (opt_daemonize && log_error_dest == disabled_my_option &&
7889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 (isatty(STDOUT_FILENO) || isatty(STDERR_FILENO))) {
7890 // Just use the default in this case.
7891 log_error_dest = "";
7892 }
7893
7894
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12063 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12069 if (opt_daemonize && !opt_validate_config) {
7895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (chdir("/") < 0) {
7896 LogErr(ERROR_LEVEL, ER_CANNOT_CHANGE_TO_ROOT_DIR, strerror(errno));
7897 unireg_abort(MYSQLD_ABORT_EXIT);
7898 }
7899
7900
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if ((pipe_write_fd = mysqld::runtime::mysqld_daemonize()) < -1) {
7901
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_FAILED_START_MYSQLD_DAEMON);
7902
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(MYSQLD_ABORT_EXIT);
7903 }
7904
7905
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (pipe_write_fd < 0) {
7906 // This is the launching process and the daemon appears to have
7907 // started ok (Need to call unireg_abort with success here to
7908 // clean up resources in the launching process.
7909
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_SUCCESS_EXIT);
7910 }
7911
7912 // Need to update the value of current_pid so that it reflects the
7913 // pid of the daemon (the previous value was set by unireg_init()
7914 // while still in the launcher process.
7915 3 current_pid = static_cast<ulong>(getpid());
7916 }
7917 #endif
7918
7919 #ifndef _WIN32
7920
1/2
✓ Branch 0 taken 12066 times.
✗ Branch 1 not taken.
12066 user_info = check_user(mysqld_user);
7921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12066 times.
12066 if (!user_info.IsVoid()) {
7922 #if HAVE_CHOWN
7923 if (unlikely(opt_initialize)) {
7924 /* need to change the owner of the freshly created data directory */
7925 MY_STAT stat;
7926 char errbuf[MYSYS_STRERROR_SIZE];
7927 bool must_chown = true;
7928
7929 /* fetch the directory's owner */
7930 if (!my_stat(mysql_real_data_home, &stat, MYF(0))) {
7931 LogErr(INFORMATION_LEVEL, ER_CANT_STAT_DATADIR, my_errno(),
7932 my_strerror(errbuf, sizeof(errbuf), my_errno()));
7933 }
7934 /* Don't change it if it's already the same as SElinux stops this */
7935 else if (stat.st_uid == user_info.pw_uid &&
7936 stat.st_gid == user_info.pw_gid)
7937 must_chown = false;
7938
7939 if (must_chown &&
7940 chown(mysql_real_data_home, user_info.pw_uid, user_info.pw_gid)) {
7941 LogErr(ERROR_LEVEL, ER_CANT_CHOWN_DATADIR, mysqld_user);
7942 unireg_abort(1);
7943 }
7944 }
7945 #endif
7946
7947 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
7948 if (locked_in_memory) // getuid() == 0 here
7949 set_effective_user(user_info);
7950 else
7951 #endif
7952 set_user(mysqld_user, user_info);
7953 }
7954 #endif // !_WIN32
7955
7956 /*
7957 initiate key migration if any one of the migration specific
7958 options are provided.
7959 */
7960
4/6
✓ Branch 0 taken 12061 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 12061 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12061 times.
12066 if (opt_keyring_migration_source || opt_keyring_migration_destination ||
7961 migrate_connect_options) {
7962 5 int exit_state = MYSQLD_ABORT_EXIT;
7963 while (true) {
7964
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Migrate_keyring mk;
7965 5 my_getopt_skip_unknown = true;
7966
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (mk.init(remaining_argc, remaining_argv, opt_keyring_migration_source,
7967 opt_keyring_migration_destination, opt_keyring_migration_user,
7968 opt_keyring_migration_host, opt_keyring_migration_password,
7969 opt_keyring_migration_socket, opt_keyring_migration_port,
7970 opt_keyring_migration_to_component)) {
7971 LogErr(ERROR_LEVEL, ER_KEYRING_MIGRATION_FAILED);
7972 log_error_dest = "stderr";
7973 flush_error_log_messages();
7974 break;
7975 }
7976
7977
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (mk.execute()) {
7978 LogErr(ERROR_LEVEL, ER_KEYRING_MIGRATION_FAILED);
7979 log_error_dest = "stderr";
7980 flush_error_log_messages();
7981 break;
7982 }
7983
7984 5 my_getopt_skip_unknown = false;
7985
8/16
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
5 LogErr(INFORMATION_LEVEL, ER_KEYRING_MIGRATION_SUCCESSFUL);
7986 5 log_error_dest = "stderr";
7987
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 flush_error_log_messages();
7988 5 exit_state = MYSQLD_SUCCESS_EXIT;
7989 5 break;
7990 5 }
7991
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5 unireg_abort(exit_state);
7992 }
7993
7994 /*
7995 We have enough space for fiddling with the argv, continue
7996 */
7997
4/4
✓ Branch 0 taken 12043 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12058 times.
24104 if (!(is_help_or_validate_option()) &&
7998
3/4
✓ Branch 0 taken 12043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12040 times.
12043 my_setwd(mysql_real_data_home, MYF(0))) {
7999 char errbuf[MYSYS_STRERROR_SIZE];
8000
8001
9/18
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
3 LogErr(ERROR_LEVEL, ER_CANT_SET_DATA_DIR, mysql_real_data_home, errno,
8002 my_strerror(errbuf, sizeof(errbuf), errno));
8003
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
3 unireg_abort(MYSQLD_ABORT_EXIT); /* purecov: inspected */
8004 }
8005
8006 /*
8007 The subsequent calls may take a long time : e.g. innodb log read.
8008 Thus set the long running service control manager timeout
8009 */
8010 #if defined(_WIN32)
8011 if (windows_service) {
8012 if (setup_service_status_cmd_processed_handle())
8013 unireg_abort(MYSQLD_ABORT_EXIT);
8014
8015 char buf[32];
8016 snprintf(buf, sizeof(buf), "T %lu", slow_start_timeout);
8017 Service_status_msg msg(buf);
8018 send_service_status(msg);
8019 }
8020 #endif
8021
8022 /* Determine default TCP port and unix socket name */
8023
1/2
✓ Branch 0 taken 12058 times.
✗ Branch 1 not taken.
12058 set_ports();
8024
8025
2/6
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11768 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12058 if (init_server_components()) unireg_abort(MYSQLD_ABORT_EXIT);
8026
8027
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 11458 times.
11768 if (!server_id_supplied)
8028
8/16
✓ Branch 0 taken 310 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 310 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 310 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 310 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 310 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 310 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 310 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 310 times.
✗ Branch 15 not taken.
310 LogErr(INFORMATION_LEVEL, ER_WARN_NO_SERVERID_SPECIFIED);
8029
8030 /* Server generates uuid after innodb is initialized. But during
8031 initialization, if tablespaces like system, redo, temporary are encrypted,
8032 they are initialized with "empty" UUID. Now UUID is available, fix the
8033 empty UUID of such tablespaces now */
8034
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 if (innodb_hton != nullptr) {
8035
2/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11768 times.
23536 if (innodb_hton->fix_tablespaces_empty_uuid != nullptr &&
8036
2/4
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11768 times.
11768 innodb_hton->fix_tablespaces_empty_uuid()) {
8037 sql_print_error(
8038 "Fixing empty UUID with InnoDB Engine failed. Please"
8039 " check if keyring plugin is loaded and execute"
8040 " \"ALTER INSTANCE ROTATE INNODB MASTER KEY\"");
8041 }
8042 // Only now, that we have server_uuid initialized we can
8043 // instruct encryption threads to do some work
8044
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 if (innodb_hton->fix_default_table_encryption != nullptr) {
8045
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 innodb_hton->fix_default_table_encryption(
8046 global_system_variables.default_table_encryption, true);
8047 }
8048 }
8049
8050 /*
8051 Add server_uuid to the sid_map. This must be done after
8052 server_uuid has been initialized in init_server_auto_options and
8053 after the binary log (and sid_map file) has been initialized in
8054 init_server_components().
8055
8056 No error message is needed: init_sid_map() prints a message.
8057
8058 Strictly speaking, this is not currently needed when
8059 opt_bin_log==0, since the variables that gtid_state->init
8060 initializes are not currently used in that case. But we call it
8061 regardless to avoid possible future bugs if gtid_state ever
8062 needs to do anything else.
8063 */
8064
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 global_sid_lock->wrlock();
8065
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 int gtid_ret = gtid_state->init();
8066
1/2
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
11768 global_sid_lock->unlock();
8067
8068
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11768 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11768 if (gtid_ret) unireg_abort(MYSQLD_ABORT_EXIT);
8069
8070
3/4
✓ Branch 0 taken 11478 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 11478 times.
✗ Branch 3 not taken.
11768 if (!opt_initialize && !opt_initialize_insecure) {
8071 // Initialize executed_gtids from mysql.gtid_executed table.
8072
2/6
✓ Branch 0 taken 11478 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11478 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11478 if (gtid_state->read_gtid_executed_from_table() == -1) unireg_abort(1);
8073 }
8074
8075
2/2
✓ Branch 0 taken 11224 times.
✓ Branch 1 taken 544 times.
11768 if (opt_bin_log) {
8076 /*
8077 Initialize GLOBAL.GTID_EXECUTED and GLOBAL.GTID_PURGED from
8078 gtid_executed table and binlog files during server startup.
8079 */
8080 Gtid_set *executed_gtids =
8081 11224 const_cast<Gtid_set *>(gtid_state->get_executed_gtids());
8082 11224 Gtid_set *lost_gtids = const_cast<Gtid_set *>(gtid_state->get_lost_gtids());
8083 Gtid_set *gtids_only_in_table =
8084 11224 const_cast<Gtid_set *>(gtid_state->get_gtids_only_in_table());
8085 Gtid_set *previous_gtids_logged =
8086 11224 const_cast<Gtid_set *>(gtid_state->get_previous_gtids_logged());
8087
8088
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 Gtid_set purged_gtids_from_binlog(global_sid_map, global_sid_lock);
8089
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 Gtid_set gtids_in_binlog(global_sid_map, global_sid_lock);
8090
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 Gtid_set gtids_in_binlog_not_in_table(global_sid_map, global_sid_lock);
8091
8092
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 if (mysql_bin_log.init_gtid_sets(
8093 &gtids_in_binlog, &purged_gtids_from_binlog,
8094 opt_source_verify_checksum, true /*true=need lock*/,
8095 nullptr /*trx_parser*/, nullptr /*partial_trx*/,
8096 true /*is_server_starting*/))
8097 unireg_abort(MYSQLD_ABORT_EXIT);
8098
8099
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 global_sid_lock->wrlock();
8100
8101
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 purged_gtids_from_binlog.dbug_print("purged_gtids_from_binlog");
8102
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 gtids_in_binlog.dbug_print("gtids_in_binlog");
8103
8104
5/6
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 10774 times.
✓ Branch 4 taken 87 times.
✓ Branch 5 taken 11137 times.
11674 if (!gtids_in_binlog.is_empty() &&
8105
3/4
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87 times.
✓ Branch 3 taken 363 times.
450 !gtids_in_binlog.is_subset(executed_gtids)) {
8106
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 gtids_in_binlog_not_in_table.add_gtid_set(&gtids_in_binlog);
8107
3/4
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 17 times.
87 if (!executed_gtids->is_empty())
8108
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 gtids_in_binlog_not_in_table.remove_gtid_set(executed_gtids);
8109 /*
8110 Save unsaved GTIDs into gtid_executed table, in the following
8111 four cases:
8112 1. the upgrade case.
8113 2. the case that a slave is provisioned from a backup of
8114 the master and the slave is cleaned by RESET MASTER
8115 and RESET SLAVE before this.
8116 3. the case that no binlog rotation happened from the
8117 last RESET MASTER on the server before it crashes.
8118 4. The set of GTIDs of the last binlog is not saved into the
8119 gtid_executed table if server crashes, so we save it into
8120 gtid_executed table and executed_gtids during recovery
8121 from the crash.
8122 */
8123
2/4
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 87 times.
87 if (gtid_state->save(&gtids_in_binlog_not_in_table) == -1) {
8124 global_sid_lock->unlock();
8125 unireg_abort(MYSQLD_ABORT_EXIT);
8126 }
8127
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 executed_gtids->add_gtid_set(&gtids_in_binlog_not_in_table);
8128 }
8129
8130 /* gtids_only_in_table= executed_gtids - gtids_in_binlog */
8131
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 if (gtids_only_in_table->add_gtid_set(executed_gtids) != RETURN_STATUS_OK) {
8132 global_sid_lock->unlock();
8133 unireg_abort(MYSQLD_ABORT_EXIT);
8134 }
8135
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 gtids_only_in_table->remove_gtid_set(&gtids_in_binlog);
8136 /*
8137 lost_gtids = executed_gtids -
8138 (gtids_in_binlog - purged_gtids_from_binlog)
8139 = gtids_only_in_table + purged_gtids_from_binlog;
8140 */
8141
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 assert(lost_gtids->is_empty());
8142
3/6
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11224 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11224 times.
22448 if (lost_gtids->add_gtid_set(gtids_only_in_table) != RETURN_STATUS_OK ||
8143
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 lost_gtids->add_gtid_set(&purged_gtids_from_binlog) !=
8144 RETURN_STATUS_OK) {
8145 global_sid_lock->unlock();
8146 unireg_abort(MYSQLD_ABORT_EXIT);
8147 }
8148
8149 /* Prepare previous_gtids_logged for next binlog */
8150
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 if (previous_gtids_logged->add_gtid_set(&gtids_in_binlog) !=
8151 RETURN_STATUS_OK) {
8152 global_sid_lock->unlock();
8153 unireg_abort(MYSQLD_ABORT_EXIT);
8154 }
8155
8156 /*
8157 Write the previous set of gtids at this point because during
8158 the creation of the binary log this is not done as we cannot
8159 move the init_gtid_sets() to a place before opening the binary
8160 log. This requires some investigation.
8161
8162 /Alfranio
8163 */
8164
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 Previous_gtids_log_event prev_gtids_ev(&gtids_in_binlog);
8165
8166
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 global_sid_lock->unlock();
8167
8168 11224 (prev_gtids_ev.common_footer)->checksum_alg =
8169 11224 static_cast<enum_binlog_checksum_alg>(binlog_checksum_options);
8170
8171
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11224 times.
11224 if (mysql_bin_log.write_event_to_binlog_and_sync(&prev_gtids_ev))
8172 unireg_abort(MYSQLD_ABORT_EXIT);
8173
8174 // run auto purge member function. It will evaluate auto purge controls
8175 // and configuration, calculate which log files are to be purged, and
8176 // if any file is to be purged, it will purge it. This is all encapsulated
8177 // insiude the auto purge member function.
8178 //
8179 // Note on the DBUG_EVALUATE_IF usage below:
8180 // - when compiling it out: the condition evaluates to true, thus
8181 // mysql_bin_log.auto_purge_at_server_startup() runs
8182 // - when "expire_logs_always_at_start" is set: evaluates to false,
8183 // thus mysql_bin_log.purge_logs_before_date() runs
8184 // - when "expire_logs_always_at_start" is not set: evaluates to true,
8185 // this mysql_bin_log.auto_purge_at_server_startup() runs
8186
2/4
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11224 times.
✗ Branch 3 not taken.
11224 if (DBUG_EVALUATE_IF("expire_logs_always_at_start", false, true))
8187
1/2
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
11224 mysql_bin_log.auto_purge_at_server_startup();
8188 else if (expire_logs_days > 0 || binlog_expire_logs_seconds > 0)
8189 mysql_bin_log.purge_logs_before_date(time(nullptr), true);
8190
8191
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11220 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
11224 if (binlog_space_limit) mysql_bin_log.purge_logs_by_size(true);
8192
8193
4/6
✓ Branch 0 taken 11224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1511 times.
✓ Branch 3 taken 9713 times.
✓ Branch 4 taken 1511 times.
✗ Branch 5 not taken.
11224 (void)RUN_HOOK(server_state, after_engine_recovery, (nullptr));
8194 11224 }
8195
8196
3/6
✓ Branch 0 taken 11768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11758 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11768 if (init_ssl_communication()) unireg_abort(MYSQLD_ABORT_EXIT);
8197
3/6
✓ Branch 0 taken 11748 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 11733 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11758 if (network_init()) unireg_abort(MYSQLD_ABORT_EXIT);
8198
8199 #ifdef _WIN32
8200 if (opt_require_secure_transport && !opt_enable_shared_memory &&
8201 !have_ssl() && !opt_initialize) {
8202 LogErr(ERROR_LEVEL, ER_TRANSPORTS_WHAT_TRANSPORTS);
8203 unireg_abort(MYSQLD_ABORT_EXIT);
8204 }
8205 #endif
8206
8207 /*
8208 Initialize my_str_malloc(), my_str_realloc() and my_str_free()
8209 */
8210 11733 my_str_malloc = &my_str_malloc_mysqld;
8211 11733 my_str_free = &my_str_free_mysqld;
8212 11733 my_str_realloc = &my_str_realloc_mysqld;
8213
8214 11733 error_handler_hook = my_message_sql;
8215
8216 11733 bool abort = false;
8217
8218 /* Save pid of this process in a file */
8219
2/2
✓ Branch 0 taken 11443 times.
✓ Branch 1 taken 290 times.
11733 if (!opt_initialize) {
8220
2/4
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11443 times.
11443 if (create_pid_file()) abort = true;
8221 }
8222
8223 /* Read the optimizer cost model configuration tables */
8224
3/4
✓ Branch 0 taken 11443 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 11443 times.
✗ Branch 3 not taken.
11733 if (!opt_initialize) reload_optimizer_cost_constants();
8225
8226 11733 if (
8227 /*
8228 Read components table to restore previously installed components. This
8229 requires read access to mysql.component table.
8230 */
8231
5/8
✓ Branch 0 taken 11443 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 11443 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11443 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 11733 times.
23466 (!opt_initialize && mysql_component_infrastructure_init()) ||
8232
2/4
✓ Branch 0 taken 11733 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11733 times.
11733 mysql_rm_tmp_tables()) {
8233 abort = true;
8234 }
8235
8236 /* we do want to exit if there are any other unknown options */
8237
1/2
✓ Branch 0 taken 11733 times.
✗ Branch 1 not taken.
11733 if (remaining_argc > 1) {
8238 int ho_error;
8239 11733 struct my_option no_opts[] = {{nullptr, 0, nullptr, nullptr, nullptr,
8240 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
8241 nullptr, 0, nullptr}};
8242 /*
8243 We need to eat any 'loose' arguments first before we conclude
8244 that there are unprocessed options.
8245 */
8246 11733 my_getopt_skip_unknown = false;
8247
8248
3/4
✓ Branch 0 taken 11733 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 11703 times.
11733 if ((ho_error = handle_options(&remaining_argc, &remaining_argv, no_opts,
8249 mysqld_get_one_option)))
8250 30 abort = true;
8251 else {
8252 /* Add back the program name handle_options removes */
8253 11703 remaining_argc++;
8254 11703 remaining_argv--;
8255 11703 my_getopt_skip_unknown = true;
8256
8257
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11700 times.
11703 if (remaining_argc > 1) {
8258
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_EXCESS_ARGUMENTS, remaining_argv[1]);
8259
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(INFORMATION_LEVEL, ER_VERBOSE_HINT);
8260 3 abort = true;
8261 }
8262 }
8263 }
8264
8265
7/8
✓ Branch 0 taken 11700 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 11692 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11691 times.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 11691 times.
11733 if (abort || acl_init(opt_noacl)) {
8266
10/18
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
34 if (!abort) LogErr(ERROR_LEVEL, ER_PRIVILEGE_SYSTEM_INIT_FAILED);
8267 34 abort = true;
8268 34 opt_noacl = true;
8269 }
8270
8271 /*
8272 if running with --initialize, explicitly allocate the memory
8273 to be used by ACL objects.
8274 */
8275
3/4
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 11435 times.
✓ Branch 2 taken 290 times.
✗ Branch 3 not taken.
11725 if (opt_initialize) init_acl_memory();
8276
8277
6/8
✓ Branch 0 taken 11691 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 11691 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11691 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 11691 times.
23416 if (abort || my_tz_init((THD *)nullptr, default_tz_name, opt_initialize) ||
8278
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
11691 grant_init(opt_noacl)) {
8279 34 set_connection_events_loop_aborted(true);
8280
8281
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 delete_pid_file(MYF(MY_WME));
8282
8283
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
34 unireg_abort(MYSQLD_ABORT_EXIT);
8284 }
8285
8286 /*
8287 Bootstrap the dynamic privilege service implementation
8288 */
8289
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
11691 if (dynamic_privilege_init()) {
8290 LogErr(WARNING_LEVEL, ER_PERSISTENT_PRIVILEGES_BOOTSTRAP);
8291 }
8292
8293 /*
8294 In the case of upgrade, the bootstrap thread would have already initialized
8295 the structures necessary for federated server from mysql.servers table.
8296 Hence we need not initialize them again here.
8297 */
8298
7/8
✓ Branch 0 taken 11405 times.
✓ Branch 1 taken 286 times.
✓ Branch 2 taken 11405 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 152 times.
✓ Branch 5 taken 11253 times.
✓ Branch 6 taken 11256 times.
✓ Branch 7 taken 435 times.
11843 if (!opt_initialize && (dd::upgrade::no_server_upgrade_required() ||
8299
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 149 times.
152 opt_upgrade_mode == UPGRADE_MINIMAL))
8300
1/2
✓ Branch 0 taken 11256 times.
✗ Branch 1 not taken.
11256 servers_init(nullptr);
8301
8302
2/2
✓ Branch 0 taken 11391 times.
✓ Branch 1 taken 300 times.
11691 if (!opt_noacl) {
8303
1/2
✓ Branch 0 taken 11391 times.
✗ Branch 1 not taken.
11391 udf_read_functions_table();
8304 }
8305
8306
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 init_status_vars();
8307 /* If running with --initialize, do not start replication. */
8308
2/2
✓ Branch 0 taken 286 times.
✓ Branch 1 taken 11405 times.
11691 if (opt_initialize) opt_skip_replica_start = true;
8309
8310
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 check_binlog_cache_size(nullptr);
8311
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 check_binlog_stmt_cache_size(nullptr);
8312
8313
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 binlog_unsafe_map_init();
8314
8315 /* If running with --initialize, do not start replication. */
8316
2/2
✓ Branch 0 taken 11405 times.
✓ Branch 1 taken 286 times.
11691 if (!opt_initialize) {
8317 // Make @@replica_skip_errors show the nice human-readable value.
8318
1/2
✓ Branch 0 taken 11405 times.
✗ Branch 1 not taken.
11405 set_replica_skip_errors(&opt_replica_skip_errors);
8319 /*
8320 Group replication filters should be discarded before init_replica(),
8321 otherwise the pre-configured filters will be referenced by group
8322 replication channels.
8323 */
8324
1/2
✓ Branch 0 taken 11405 times.
✗ Branch 1 not taken.
11405 rpl_channel_filters.discard_group_replication_filters();
8325
8326 /*
8327 init_replica() must be called after the thread keys are created.
8328 */
8329
2/2
✓ Branch 0 taken 11397 times.
✓ Branch 1 taken 8 times.
11405 if (server_id != 0)
8330
1/2
✓ Branch 0 taken 11397 times.
✗ Branch 1 not taken.
11397 init_replica(); /* Ignoring errors while configuring replication. */
8331
8332 /*
8333 If the user specifies a per-channel replication filter through a
8334 command-line option (or in a configuration file) for a slave
8335 replication channel which does not exist as of now (i.e not
8336 present in slave info tables yet), then the per-channel
8337 replication filter is discarded with a warning.
8338 If the user specifies a per-channel replication filter through
8339 a command-line option (or in a configuration file) for group
8340 replication channels 'group_replication_recovery' and
8341 'group_replication_applier' which is disallowed, then the
8342 per-channel replication filter is discarded with a warning.
8343 */
8344
1/2
✓ Branch 0 taken 11405 times.
✗ Branch 1 not taken.
11405 rpl_channel_filters.discard_all_unattached_filters();
8345 }
8346
8347 #ifdef WITH_LOCK_ORDER
8348 if (!opt_initialize) {
8349 LO_activate();
8350 }
8351 #endif /* WITH_LOCK_ORDER */
8352
8353 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
8354
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 initialize_performance_schema_acl(opt_initialize);
8355 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
8356
8357
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 initialize_information_schema_acl();
8358
8359
4/6
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1514 times.
✓ Branch 3 taken 10177 times.
✓ Branch 4 taken 1514 times.
✗ Branch 5 not taken.
11691 (void)RUN_HOOK(server_state, after_recovery, (nullptr));
8360
8361
5/8
✓ Branch 0 taken 11391 times.
✓ Branch 1 taken 300 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11391 times.
✓ Branch 4 taken 11691 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 11691 times.
11691 if (Events::init(opt_noacl || opt_initialize))
8362 unireg_abort(MYSQLD_ABORT_EXIT);
8363
8364 #ifndef _WIN32
8365 // Start signal handler thread.
8366
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 start_signal_handler();
8367 #endif
8368
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
23382 if (opt_authentication_policy &&
8369
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
11691 validate_authentication_policy(opt_authentication_policy)) {
8370 /* --authentication_policy is set to invalid value */
8371 LogErr(ERROR_LEVEL, ER_INVALID_AUTHENTICATION_POLICY);
8372 return 1;
8373 } else {
8374 /* update the value */
8375
1/2
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
11691 update_authentication_policy();
8376 }
8377 /* set all persistent options */
8378
2/4
✓ Branch 0 taken 11691 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11691 times.
11691 if (persisted_variables_cache.set_persisted_options(false)) {
8379 LogErr(ERROR_LEVEL, ER_CANT_SET_UP_PERSISTED_VALUES);
8380 flush_error_log_messages();
8381 return 1;
8382 }
8383
8384 /*
8385 Invoke the bootstrap thread, if required.
8386 */
8387
1/2
✓ Branch 0 taken 11405 times.
✗ Branch 1 not taken.
11691 process_bootstrap();
8388
8389 /*
8390 Event must be invoked after error_handler_hook is assigned to
8391 my_message_sql, otherwise my_message will not cause the event to abort.
8392 */
8393 11405 void *argv_p = argv;
8394
2/4
✓ Branch 0 taken 11405 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11405 times.
11405 if (mysql_audit_notify(AUDIT_EVENT(MYSQL_AUDIT_SERVER_STARTUP_STARTUP),
8395 static_cast<const char **>(argv_p), argc))
8396 unireg_abort(MYSQLD_ABORT_EXIT);
8397
8398 #ifdef _WIN32
8399 create_shutdown_and_restart_thread();
8400 #endif
8401
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11401 times.
11405 if (mysqld_process_must_end_at_startup) {
8402 #if !defined(_WIN32)
8403
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if (opt_daemonize) mysqld::runtime::signal_parent(pipe_write_fd, 1);
8404 #endif
8405
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
4 unireg_abort(MYSQLD_SUCCESS_EXIT);
8406 }
8407
8408
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 start_handle_manager();
8409
8410
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 create_compress_gtid_table_thread();
8411
8412
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
22802 LogEvent()
8413
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 .type(LOG_TYPE_ERROR)
8414
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 .subsys(LOG_SUBSYSTEM_TAG)
8415
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 .prio(SYSTEM_LEVEL)
8416
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11401 times.
✓ Branch 2 taken 11401 times.
✗ Branch 3 not taken.
11401 .lookup(ER_SERVER_STARTUP_MSG, my_progname, server_version,
8417 #ifdef HAVE_SYS_UN_H
8418 (opt_initialize ? "" : mysqld_unix_port),
8419 #else
8420 "",
8421 #endif
8422 mysqld_port, MYSQL_COMPILATION_COMMENT_SERVER);
8423
8424
4/4
✓ Branch 0 taken 11380 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 11353 times.
11401 if (!opt_disable_networking && my_admin_bind_addr_str)
8425
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
54 LogEvent()
8426
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .type(LOG_TYPE_ERROR)
8427
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .subsys(LOG_SUBSYSTEM_TAG)
8428
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .prio(SYSTEM_LEVEL)
8429
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .lookup(ER_SERVER_STARTUP_ADMIN_INTERFACE, my_admin_bind_addr_str,
8430 mysqld_admin_port, MYSQL_COMPILATION_COMMENT);
8431
8432 #if defined(_WIN32)
8433 if (windows_service) {
8434 Service_status_msg s("R");
8435 send_service_status(s);
8436 }
8437 #endif
8438
8439
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 server_components_initialized();
8440
8441 /*
8442 Set opt_super_readonly here because if opt_super_readonly is set
8443 in get_option, it will create problem while setting up event scheduler.
8444 */
8445 11401 set_super_read_only_post_init();
8446
8447
3/8
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11401 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11401 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
11401 DBUG_PRINT("info", ("Block, listening for incoming connections"));
8448
8449
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 (void)MYSQL_SET_STAGE(0, __FILE__, __LINE__);
8450
8451 11401 server_operational_state = SERVER_OPERATING;
8452
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 sysd::notify("READY=1\nSTATUS=Server is operational\nMAIN_PID=", getpid(),
8453 "\n");
8454
8455
4/6
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1514 times.
✓ Branch 3 taken 9887 times.
✓ Branch 4 taken 1514 times.
✗ Branch 5 not taken.
11401 (void)RUN_HOOK(server_state, before_handle_connection, (nullptr));
8456
8457 #if defined(_WIN32)
8458 if (mysqld_socket_acceptor != nullptr)
8459 mysqld_socket_acceptor->check_and_spawn_admin_connection_handler_thread();
8460 setup_conn_event_handler_threads();
8461 #else
8462
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 mysql_mutex_lock(&LOCK_socket_listener_active);
8463 // Make it possible for the signal handler to kill the listener.
8464 11401 socket_listener_active = true;
8465
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 mysql_mutex_unlock(&LOCK_socket_listener_active);
8466
8467
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11399 times.
11401 if (opt_daemonize) {
8468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (nstdout != nullptr) {
8469 // Show the pid on stdout if daemonizing and connected to tty
8470 fprintf(nstdout, "mysqld is running as pid %lu\n", current_pid);
8471 fclose(nstdout);
8472 nstdout = nullptr;
8473 }
8474
8475
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mysqld::runtime::signal_parent(pipe_write_fd, 1);
8476 }
8477
8478
1/2
✓ Branch 0 taken 11401 times.
✗ Branch 1 not taken.
11401 mysqld_socket_acceptor->check_and_spawn_admin_connection_handler_thread();
8479
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
11401 mysqld_socket_acceptor->connection_event_loop();
8480 #endif /* _WIN32 */
8481 9813 server_operational_state = SERVER_SHUTTING_DOWN;
8482
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 sysd::notify("STOPPING=1\nSTATUS=Server shutdown in progress\n");
8483
8484
3/8
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9813 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9813 DBUG_PRINT("info", ("No longer listening for incoming connections"));
8485
8486
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN,
8487 MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
8488 MYSQLD_SUCCESS_EXIT);
8489
8490
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 terminate_compress_gtid_table_thread();
8491 /*
8492 Save set of GTIDs of the last binlog into gtid_executed table
8493 on server shutdown.
8494 */
8495
2/2
✓ Branch 0 taken 9688 times.
✓ Branch 1 taken 125 times.
9813 if (opt_bin_log)
8496
3/4
✓ Branch 0 taken 9688 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9685 times.
9688 if (gtid_state->save_gtids_of_last_binlog_into_table())
8497
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_CANT_SAVE_GTIDS);
8498
8499 #ifndef _WIN32
8500
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_mutex_lock(&LOCK_socket_listener_active);
8501 // Notify the signal handler that we have stopped listening for connections.
8502 9813 socket_listener_active = false;
8503
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_cond_broadcast(&COND_socket_listener_active);
8504
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_mutex_unlock(&LOCK_socket_listener_active);
8505 #endif // !_WIN32
8506
8507 #ifdef HAVE_PSI_THREAD_INTERFACE
8508 /*
8509 Disable the main thread instrumentation,
8510 to avoid recording events during the shutdown.
8511 */
8512
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 PSI_THREAD_CALL(delete_current_thread)();
8513 #endif /* HAVE_PSI_THREAD_INTERFACE */
8514
8515
3/8
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9813 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9813 DBUG_PRINT("info", ("Waiting for shutdown proceed"));
8516 9813 int ret = 0;
8517 #ifdef _WIN32
8518 if (shutdown_restart_thr_handle.handle)
8519 ret = my_thread_join(&shutdown_restart_thr_handle, NULL);
8520 shutdown_restart_thr_handle.handle = NULL;
8521 if (0 != ret)
8522 LogErr(WARNING_LEVEL, ER_CANT_JOIN_SHUTDOWN_THREAD, "shutdown ", ret);
8523 #else
8524
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (signal_thread_id.thread != 0)
8525
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 ret = my_thread_join(&signal_thread_id, nullptr);
8526 9813 signal_thread_id.thread = 0;
8527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (0 != ret)
8528 LogErr(WARNING_LEVEL, ER_CANT_JOIN_SHUTDOWN_THREAD, "signal_", ret);
8529 #endif // _WIN32
8530
8531
1/2
✓ Branch 0 taken 9795 times.
✗ Branch 1 not taken.
9813 clean_up(true);
8532 9795 mysqld_exit(signal_hand_thr_exit_code);
8533 }
8534
8535 /****************************************************************************
8536 Main and thread entry function for Win32
8537 (all this is needed only to run mysqld as a service on WinNT)
8538 ****************************************************************************/
8539
8540 #if defined(_WIN32)
8541
8542 bool is_windows_service() { return windows_service; }
8543
8544 NTService *get_win_service_ptr() { return &Service; }
8545
8546 int mysql_service(void *p) {
8547 int my_argc;
8548 char **my_argv;
8549
8550 if (use_opt_args) {
8551 my_argc = opt_argc;
8552 my_argv = opt_argv;
8553 } else if (is_mysqld_monitor()) {
8554 my_argc = Service.my_argc;
8555 my_argv = Service.my_argv;
8556 } else {
8557 my_argc = my_global_argc;
8558 my_argv = my_global_argv;
8559 }
8560
8561 if (!mysqld_early_option) {
8562 int res = start_monitor();
8563 if (res != -1) {
8564 deinitialize_mysqld_monitor();
8565 return res;
8566 }
8567 }
8568
8569 if (my_thread_init()) {
8570 flush_error_log_messages();
8571 return 1;
8572 }
8573
8574 win_main(my_argc, my_argv);
8575
8576 my_thread_end();
8577 return 0;
8578 }
8579
8580 /* Quote string if it contains space, else copy */
8581
8582 static char *add_quoted_string(char *to, const char *from, char *to_end) {
8583 uint length = (uint)(to_end - to);
8584
8585 if (!strchr(from, ' ')) return strmake(to, from, length - 1);
8586 return strxnmov(to, length - 1, "\"", from, "\"", NullS);
8587 }
8588
8589 /**
8590 Handle basic handling of services, like installation and removal.
8591
8592 @param argv Pointer to argument list
8593 @param servicename Internal name of service
8594 @param displayname Display name of service (in taskbar ?)
8595 @param file_path Path to this program
8596 @param startup_option Startup option to mysqld
8597
8598 @retval
8599 0 option handled
8600 @retval
8601 1 Could not handle option
8602 */
8603
8604 static bool default_service_handling(char **argv, const char *servicename,
8605 const char *displayname,
8606 const char *file_path,
8607 const char *extra_opt,
8608 const char *account_name) {
8609 char path_and_service[FN_REFLEN + FN_REFLEN + 32], *pos, *end;
8610 const char *opt_delim;
8611 end = path_and_service + sizeof(path_and_service) - 3;
8612
8613 /* We have to quote filename if it contains spaces */
8614 pos = add_quoted_string(path_and_service, file_path, end);
8615 if (extra_opt && *extra_opt) {
8616 /*
8617 Add option after file_path. There will be zero or one extra option. It's
8618 assumed to be --defaults-file=file but isn't checked. The variable (not
8619 the option name) should be quoted if it contains a string.
8620 */
8621 *pos++ = ' ';
8622 if (opt_delim = strchr(extra_opt, '=')) {
8623 size_t length = ++opt_delim - extra_opt;
8624 pos = my_stpnmov(pos, extra_opt, length);
8625 } else
8626 opt_delim = extra_opt;
8627
8628 pos = add_quoted_string(pos, opt_delim, end);
8629 }
8630 /* We must have servicename last */
8631 *pos++ = ' ';
8632 (void)add_quoted_string(pos, servicename, end);
8633
8634 if (Service.got_service_option(argv, "install")) {
8635 Service.Install(1, servicename, displayname, path_and_service,
8636 account_name);
8637 return 0;
8638 }
8639 if (Service.got_service_option(argv, "install-manual")) {
8640 Service.Install(0, servicename, displayname, path_and_service,
8641 account_name);
8642 return 0;
8643 }
8644 if (Service.got_service_option(argv, "remove")) {
8645 Service.Remove(servicename);
8646 return 0;
8647 }
8648 return 1;
8649 }
8650
8651 int mysqld_main(int argc, char **argv) {
8652 bool mysqld_monitor = false;
8653 mysqld_early_option = is_early_option(argc, argv);
8654
8655 if (!mysqld_early_option) {
8656 initialize_mysqld_monitor();
8657 mysqld_monitor = is_mysqld_monitor();
8658 }
8659
8660 if (mysqld_early_option || !mysqld_monitor) {
8661 /*
8662 When several instances are running on the same machine, we
8663 need to have an unique named hEventShudown through the
8664 application PID e.g.: MySQLShutdown1890; MySQLShutdown2342
8665 */
8666
8667 longlong10_to_str(GetCurrentProcessId(),
8668 my_stpcpy(shutdown_event_name, "MYSQLShutdown"), 10);
8669 longlong10_to_str(GetCurrentProcessId(),
8670 my_stpcpy(restart_event_name, "MYSQLRestart"), 10);
8671 }
8672
8673 /* Must be initialized early for comparison of service name */
8674 system_charset_info = &my_charset_utf8_general_ci;
8675
8676 if (mysqld_early_option || !mysqld_monitor) {
8677 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
8678 pre_initialize_performance_schema();
8679 #endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
8680
8681 if (my_init()) {
8682 LogErr(ERROR_LEVEL, ER_MYINIT_FAILED);
8683 flush_error_log_messages();
8684 return 1;
8685 }
8686 }
8687
8688 if (mysqld_monitor) /* true NT family */
8689 {
8690 char file_path[FN_REFLEN];
8691 my_path(file_path, argv[0], ""); /* Find name in path */
8692 fn_format(file_path, argv[0], file_path, "",
8693 MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
8694
8695 if (argc == 2) {
8696 if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
8697 file_path, "", NULL))
8698 return 0;
8699 if (Service.IsService(argv[1])) /* Start an optional service */
8700 {
8701 /*
8702 Only add the service name to the groups read from the config file
8703 if it's not "MySQL". (The default service name should be 'mysqld'
8704 but we started a bad tradition by calling it MySQL from the start
8705 and we are now stuck with it.
8706 */
8707 if (my_strcasecmp(system_charset_info, argv[1], "mysql"))
8708 load_default_groups[load_default_groups_sz - 2] = argv[1];
8709 windows_service = true;
8710
8711 Service.Init(argv[1], mysql_service);
8712 return 0;
8713 }
8714 } else if (argc == 3) /* install or remove any optional service */
8715 {
8716 if (!default_service_handling(argv, argv[2], argv[2], file_path, "",
8717 NULL))
8718 return 0;
8719 if (Service.IsService(argv[2])) {
8720 /*
8721 mysqld was started as
8722 mysqld --defaults-file=my_path\my.ini service-name
8723 */
8724 use_opt_args = 1;
8725 opt_argc = 2; // Skip service-name
8726 opt_argv = argv;
8727 windows_service = true;
8728 if (my_strcasecmp(system_charset_info, argv[2], "mysql"))
8729 load_default_groups[load_default_groups_sz - 2] = argv[2];
8730 Service.Init(argv[2], mysql_service);
8731 return 0;
8732 }
8733 } else if (argc == 4 || argc == 5) {
8734 /*
8735 This may seem strange, because we handle --local-service while
8736 preserving 4.1's behavior of allowing any one other argument that is
8737 passed to the service on startup. (The assumption is that this is
8738 --defaults-file=file, but that was not enforced in 4.1, so we don't
8739 enforce it here.)
8740 */
8741 const char *extra_opt = NullS;
8742 const char *account_name = NullS;
8743 int index;
8744 for (index = 3; index < argc; index++) {
8745 if (!strcmp(argv[index], "--local-service"))
8746 account_name = "NT AUTHORITY\\LocalService";
8747 else
8748 extra_opt = argv[index];
8749 }
8750
8751 if (argc == 4 || account_name)
8752 if (!default_service_handling(argv, argv[2], argv[2], file_path,
8753 extra_opt, account_name))
8754 return 0;
8755 } else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME)) {
8756 /* start the default service */
8757 windows_service = true;
8758 Service.Init(MYSQL_SERVICENAME, mysql_service);
8759 return 0;
8760 }
8761 }
8762
8763 // Set windows_service value in mysqld
8764 if (!mysqld_monitor) {
8765 windows_service = is_monitor_win_service();
8766
8767 if (windows_service) {
8768 if (argc == 2 && Service.IsService(argv[1])) {
8769 if (my_strcasecmp(system_charset_info, argv[1], "mysql"))
8770 load_default_groups[load_default_groups_sz - 2] = argv[1];
8771 argc--;
8772
8773 } else if (argc == 3 && Service.IsService(argv[2])) {
8774 /*
8775 mysqld was started as
8776 mysqld --defaults-file=my_path\my.ini service-name
8777 */
8778 if (my_strcasecmp(system_charset_info, argv[2], "mysql"))
8779 load_default_groups[load_default_groups_sz - 2] = argv[2];
8780 argc--;
8781 }
8782 }
8783
8784 my_global_argc = argc;
8785 my_global_argv = argv;
8786 } else {
8787 Service.my_argc = argc;
8788 Service.my_argv = argv;
8789 }
8790
8791 return mysql_service(NULL);
8792 }
8793 #endif // _WIN32
8794
8795 /**
8796 Execute the bootstrap thread, if required.
8797
8798 When mysqld is started with --initialize only,
8799 the bootstrap thread executes
8800 - compiled in statements.
8801 - create the non-DD based INFORMATION_SCHEMA.
8802 and the server exits.
8803
8804 When mysqld is started with --init-file only,
8805 the bootstrap thread executes SQL statements provided
8806 in the input text file,
8807 and the server continues and serves requests.
8808
8809 When mysqld is started with both --initialize and --init-file,
8810 the bootstrap thread:
8811 - executes compiled in statements,
8812 - executes SQL statements in the --init-file.
8813 - creates the non-DD based INFORMATION_SCHEMA.
8814 The server then exits.
8815
8816 Compiled in statements are executed in a privileged mode,
8817 with SYSTEM_THREAD_SERVER_INITIALIZE.
8818
8819 @see handle_bootstrap_impl
8820 */
8821 11691 static void process_bootstrap() {
8822 11691 MYSQL_FILE *init_file = nullptr;
8823 11691 const char *init_file_name = nullptr;
8824 enum_thread_type system_thread;
8825 11691 bool need_bootstrap = false;
8826
8827
2/2
✓ Branch 0 taken 286 times.
✓ Branch 1 taken 11405 times.
11691 if (opt_initialize) {
8828 // Make sure we can process SIGHUP during bootstrap.
8829 286 server_components_initialized();
8830 286 need_bootstrap = true;
8831 286 system_thread = SYSTEM_THREAD_SERVER_INITIALIZE;
8832 } else {
8833 11405 system_thread = SYSTEM_THREAD_INIT_FILE;
8834 }
8835
8836
2/2
✓ Branch 0 taken 275 times.
✓ Branch 1 taken 11416 times.
11691 if (opt_init_file != nullptr) {
8837
2/2
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 1 times.
275 if (*opt_init_file != '\0') {
8838 274 init_file_name = opt_init_file;
8839
7/14
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 274 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 274 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 274 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 274 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 274 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 274 times.
✗ Branch 13 not taken.
274 LogErr(INFORMATION_LEVEL, ER_BEG_INITFILE, init_file_name);
8840
8841 274 init_file = mysql_file_fopen(key_file_init, init_file_name, O_RDONLY,
8842 MYF(MY_WME));
8843 274 need_bootstrap = true;
8844 }
8845
8846
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 273 times.
275 if (init_file == nullptr) {
8847
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL, ER_INIT_CANT_OPEN_BOOTSTRAP_FILE, init_file_name);
8848 2 unireg_abort(MYSQLD_ABORT_EXIT);
8849 }
8850 }
8851
8852
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 11383 times.
11689 if (need_bootstrap) {
8853 306 bool error = bootstrap::run_bootstrap_thread(init_file_name, init_file,
8854 nullptr, system_thread);
8855
8856
2/2
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 33 times.
306 if (init_file != nullptr) {
8857 273 mysql_file_fclose(init_file, MYF(MY_WME));
8858
7/14
✓ Branch 0 taken 273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 273 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 273 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 273 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 273 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 273 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 273 times.
✗ Branch 13 not taken.
273 LogErr(INFORMATION_LEVEL, ER_END_INITFILE, init_file_name);
8859 }
8860
8861
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 295 times.
306 if (error) {
8862 /* Abort during system initialization, but not init-file execution */
8863
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 if (system_thread == SYSTEM_THREAD_SERVER_INITIALIZE) {
8864 4 unireg_abort(MYSQLD_ABORT_EXIT);
8865 }
8866 }
8867
8868
2/2
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 22 times.
302 if (opt_initialize) {
8869 // Create non DD based system views during --initialize.
8870 280 error = dd::init(
8871 dd::enum_dd_init_type::DD_INITIALIZE_NON_DD_BASED_SYSTEM_VIEWS);
8872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if (error != 0) {
8873 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
8874 unireg_abort(MYSQLD_ABORT_EXIT);
8875 }
8876
8877 280 unireg_abort(MYSQLD_SUCCESS_EXIT);
8878 }
8879 }
8880
8881 11405 return;
8882 }
8883
8884 /****************************************************************************
8885 Handle start options
8886 ******************************************************************************/
8887
8888 /**
8889 Process command line options but use only "help", "initialize",
8890 "initialize-insecure". If one of these options exists then change default
8891 value of log_error_verbosity.
8892 */
8893 12109 static void adjust_log_error_verbosity(vector<my_option> *all_early_options) {
8894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12109 times.
12109 if (remaining_argc <= 1) return;
8895
8896 /* create a copy of remaining_argv */
8897 12109 int copy_argc = remaining_argc;
8898 12109 vector<char *> copy_argv;
8899
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 copy_argv.reserve(copy_argc + 1);
8900
3/4
✓ Branch 0 taken 914800 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 914800 times.
✓ Branch 3 taken 12109 times.
926909 for (int i = 0; i < copy_argc; i++) copy_argv.push_back(remaining_argv[i]);
8901
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 copy_argv.push_back(nullptr);
8902
8903 /* select only "help", "initialize", "initialize-insecure" options */
8904 12109 vector<my_option> init_options;
8905 static const vector<const char *> opt_names{"help", "initialize",
8906
3/8
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12109 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12109 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12109 "initialize-insecure"};
8907
2/2
✓ Branch 0 taken 254289 times.
✓ Branch 1 taken 12109 times.
266398 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++)
8908
1/2
✓ Branch 0 taken 254289 times.
✗ Branch 1 not taken.
254289 if (std::find(opt_names.cbegin(), opt_names.cend(), opt->name) !=
8909
2/2
✓ Branch 0 taken 36327 times.
✓ Branch 1 taken 217962 times.
508578 opt_names.cend())
8910
1/2
✓ Branch 0 taken 36327 times.
✗ Branch 1 not taken.
36327 init_options.push_back(*opt);
8911
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 add_terminator(&init_options);
8912
8913 12109 char **copy_argv_ptr = &copy_argv[0];
8914
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 int ho_error = handle_options(&copy_argc, &copy_argv_ptr, &init_options[0],
8915 mysqld_get_one_option);
8916
8917
3/4
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12095 times.
✓ Branch 3 taken 14 times.
12109 if ((ho_error == 0) &&
8918
4/4
✓ Branch 0 taken 12079 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 284 times.
✓ Branch 3 taken 11795 times.
12095 (opt_help || opt_initialize || opt_initialize_insecure)) {
8919 /*
8920 Show errors during --help, but mute everything else so the info the
8921 user actually wants isn't lost in the spam. (For --help --verbose,
8922 we need to set up far enough to be able to print variables provided
8923 by plugins, so a good number of warnings/notes might get printed.)
8924 Likewise for --initialize.
8925 */
8926
2/2
✓ Branch 0 taken 30458 times.
✓ Branch 1 taken 314 times.
30772 for (my_option *opt = &(*all_early_options)[0]; opt->name; opt++)
8927
2/2
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 30144 times.
30458 if (!strcmp("log_error_verbosity", opt->name)) {
8928
4/4
✓ Branch 0 taken 298 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 285 times.
✓ Branch 3 taken 13 times.
314 opt->def_value = (opt_initialize || opt_initialize_insecure) ? 2 : 1;
8929 }
8930 }
8931 12109 }
8932
8933 /**
8934 Process command line options flagged as 'early'.
8935 Some components needs to be initialized as early as possible,
8936 because the rest of the server initialization depends on them.
8937 Options that needs to be parsed early includes:
8938 - the performance schema, when compiled in,
8939 - options related to the help,
8940 - options related to the bootstrap
8941 The performance schema needs to be initialized as early as possible,
8942 before to-be-instrumented objects of the server are initialized.
8943 */
8944 12109 static int handle_early_options() {
8945 int ho_error;
8946 12109 vector<my_option> all_early_options;
8947
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 all_early_options.reserve(100);
8948
8949
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 my_getopt_register_get_addr(nullptr);
8950 /* Skip unknown options so that they may be processed later */
8951 12109 my_getopt_skip_unknown = true;
8952
8953 /* Add the system variables parsed early */
8954
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY);
8955
8956 /* Add the command line options parsed early */
8957
2/2
✓ Branch 0 taken 254289 times.
✓ Branch 1 taken 12109 times.
266398 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++)
8958
1/2
✓ Branch 0 taken 254289 times.
✗ Branch 1 not taken.
254289 all_early_options.push_back(*opt);
8959
8960
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 add_terminator(&all_early_options);
8961
8962 12109 my_getopt_error_reporter = option_error_reporter;
8963 12109 my_charset_error_reporter = charset_error_reporter;
8964
8965
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 adjust_log_error_verbosity(&all_early_options);
8966
8967
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 ho_error = handle_options(&remaining_argc, &remaining_argv,
8968 12109 &all_early_options[0], mysqld_get_one_option);
8969
8970
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 if (ho_error == 0) {
8971 /* update verbosity in filter engine, if needed */
8972
1/2
✓ Branch 0 taken 12109 times.
✗ Branch 1 not taken.
12109 log_builtins_filter_update_verbosity(log_error_verbosity);
8973
8974 /* Add back the program name handle_options removes */
8975 12109 remaining_argc++;
8976 12109 remaining_argv--;
8977
8978
2/2
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 11824 times.
12109 if (opt_initialize_insecure) opt_initialize = true;
8979
8980
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12107 times.
12109 if (opt_debugging) {
8981 /* Allow break with SIGINT, no core or stack trace */
8982 2 test_flags |= TEST_SIGINT | TEST_NO_STACKTRACE;
8983 2 test_flags &= ~TEST_CORE_ON_SIGNAL;
8984 }
8985 }
8986
8987 // Swap with an empty vector, i.e. delete elements and free allocated space.
8988 12109 vector<my_option>().swap(all_early_options);
8989
8990 12109 return ho_error;
8991 12109 }
8992
8993 /**
8994 Adjust @c open_files_limit.
8995 Computation is based on:
8996 - @c max_connections,
8997 - @c table_cache_size,
8998 - the platform max open file limit.
8999 */
9000 12104 static void adjust_open_files_limit(ulong *requested_open_files) {
9001 ulong limit_1;
9002 ulong limit_2;
9003 ulong limit_3;
9004 ulong request_open_files;
9005 ulong effective_open_files;
9006
9007 /* MyISAM requires two file handles per table. */
9008 12104 limit_1 = 10 + max_connections + table_cache_size * 2;
9009
9010 /*
9011 We are trying to allocate no less than max_connections*5 file
9012 handles (i.e. we are trying to set the limit so that they will
9013 be available).
9014 */
9015 12104 limit_2 = max_connections * 5;
9016
9017 /* Try to allocate no less than 5000 by default. */
9018
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12101 times.
12104 limit_3 = open_files_limit ? open_files_limit : 5000;
9019
9020 12104 request_open_files = max<ulong>(max<ulong>(limit_1, limit_2), limit_3);
9021
9022 /* Notice: my_set_max_open_files() may return more than requested. */
9023
1/2
✓ Branch 0 taken 12104 times.
✗ Branch 1 not taken.
12104 effective_open_files = my_set_max_open_files(request_open_files);
9024
9025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12104 times.
12104 if (effective_open_files < request_open_files) {
9026 if (open_files_limit == 0) {
9027 LogErr(WARNING_LEVEL, ER_CHANGED_MAX_OPEN_FILES, effective_open_files,
9028 request_open_files);
9029 } else {
9030 LogErr(WARNING_LEVEL, ER_CANT_INCREASE_MAX_OPEN_FILES,
9031 effective_open_files, request_open_files);
9032 }
9033 }
9034
9035 12104 open_files_limit = effective_open_files;
9036
1/2
✓ Branch 0 taken 12104 times.
✗ Branch 1 not taken.
12104 if (requested_open_files)
9037 12104 *requested_open_files =
9038 12104 min<ulong>(effective_open_files, request_open_files);
9039 12104 }
9040
9041 static constexpr const ulong TABLE_OPEN_CACHE_MIN{400};
9042
9043 12104 static void adjust_max_connections(ulong requested_open_files) {
9044 ulong limit;
9045
9046 12104 limit = requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;
9047
9048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12104 times.
12104 if (limit < max_connections) {
9049 LogErr(WARNING_LEVEL, ER_CHANGED_MAX_CONNECTIONS, limit, max_connections);
9050
9051 // This can be done unprotected since it is only called on startup.
9052 max_connections = limit;
9053 }
9054 12104 }
9055
9056 12104 static void adjust_table_cache_size(ulong requested_open_files) {
9057 ulong limit;
9058
9059 12104 limit = max<ulong>((requested_open_files - 10 - max_connections) / 2,
9060 TABLE_OPEN_CACHE_MIN);
9061
9062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12104 times.
12104 if (limit < table_cache_size) {
9063 LogErr(WARNING_LEVEL, ER_CHANGED_TABLE_OPEN_CACHE, limit, table_cache_size);
9064
9065 table_cache_size = limit;
9066 }
9067
9068 12104 table_cache_size_per_instance = table_cache_size / table_cache_instances;
9069 12104 }
9070
9071 12104 static void adjust_table_def_size() {
9072 ulong default_value;
9073 sys_var *var;
9074
9075 12104 default_value = min<ulong>(400 + table_cache_size / 2, 2000);
9076
2/4
✓ Branch 0 taken 12104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12104 times.
✗ Branch 3 not taken.
12104 var = find_static_system_variable("table_definition_cache");
9077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12104 times.
12104 assert(var != nullptr);
9078 12104 var->update_default(default_value);
9079
9080
2/2
✓ Branch 0 taken 12102 times.
✓ Branch 1 taken 2 times.
12104 if (!table_definition_cache_specified) table_def_size = default_value;
9081 12104 }
9082
9083 12104 static void adjust_related_options(ulong *requested_open_files) {
9084 /*
9085 In bootstrap, disable grant tables (about to be created)
9086 */
9087
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 11803 times.
12104 if (opt_initialize) opt_noacl = true;
9088
9089 /* The order is critical here, because of dependencies. */
9090 12104 adjust_open_files_limit(requested_open_files);
9091 12104 adjust_max_connections(*requested_open_files);
9092 12104 adjust_table_cache_size(*requested_open_files);
9093 12104 adjust_table_def_size();
9094 12104 }
9095
9096 vector<my_option> all_options;
9097
9098 struct my_option my_long_early_options[] = {
9099 #if !defined(_WIN32)
9100 {"daemonize", 'D', "Run mysqld as sysv daemon", &opt_daemonize,
9101 &opt_daemonize, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9102 #endif
9103 {"skip-grant-tables", 0,
9104 "Start without grant tables. This gives all users FULL ACCESS to all "
9105 "tables.",
9106 &opt_noacl, &opt_noacl, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
9107 nullptr},
9108 {"help", '?', "Display this help and exit.", &opt_help, &opt_help, nullptr,
9109 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9110 {"verbose", 'v', "Used with --help option for detailed help.", &opt_verbose,
9111 &opt_verbose, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9112 {"version", 'V', "Output version information and exit.", nullptr, nullptr,
9113 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9114 {"initialize", 'I',
9115 "Create the default database and exit."
9116 " Create a super user with a random expired password and store it into "
9117 "the log.",
9118 &opt_initialize, &opt_initialize, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
9119 nullptr, 0, nullptr},
9120 {"initialize-insecure", 0,
9121 "Create the default database and exit."
9122 " Create a super user with empty password.",
9123 &opt_initialize_insecure, &opt_initialize_insecure, nullptr, GET_BOOL,
9124 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9125 {"keyring-migration-source", OPT_KEYRING_MIGRATION_SOURCE,
9126 "Keyring plugin from where the keys needs to "
9127 "be migrated to. This option must be specified along with "
9128 "--keyring-migration-destination.",
9129 &opt_keyring_migration_source, &opt_keyring_migration_source, nullptr,
9130 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9131 {"keyring-migration-destination", OPT_KEYRING_MIGRATION_DESTINATION,
9132 "Keyring plugin or component to which the keys are migrated to.",
9133 &opt_keyring_migration_destination, &opt_keyring_migration_destination,
9134 nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9135 {"keyring-migration-user", OPT_KEYRING_MIGRATION_USER,
9136 "User to login to server.", &opt_keyring_migration_user,
9137 &opt_keyring_migration_user, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9138 nullptr, 0, nullptr},
9139 {"keyring-migration-host", OPT_KEYRING_MIGRATION_HOST, "Connect to host.",
9140 &opt_keyring_migration_host, &opt_keyring_migration_host, nullptr, GET_STR,
9141 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9142 {"keyring-migration-password", 'p',
9143 "Password to use when connecting to server during keyring migration. "
9144 "If password value is not specified then it will be asked from the tty.",
9145 nullptr, nullptr, nullptr, GET_PASSWORD, OPT_ARG, 0, 0, 0, nullptr, 0,
9146 nullptr},
9147 {"keyring-migration-socket", OPT_KEYRING_MIGRATION_SOCKET,
9148 "The socket file to use for connection.", &opt_keyring_migration_socket,
9149 &opt_keyring_migration_socket, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9150 nullptr, 0, nullptr},
9151 {"keyring-migration-port", OPT_KEYRING_MIGRATION_PORT,
9152 "Port number to use for connection.", &opt_keyring_migration_port,
9153 &opt_keyring_migration_port, nullptr, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
9154 nullptr, 0, nullptr},
9155 {"keyring-migration-to-component", OPT_KEYRING_MIGRATION_TO_COMPONENT,
9156 "Migrate from keyring plugin to keyring component.",
9157 &opt_keyring_migration_to_component, &opt_keyring_migration_to_component,
9158 nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9159 {"no-dd-upgrade", 0,
9160 "Abort restart if automatic upgrade or downgrade of the data dictionary "
9161 "is needed. Deprecated option. Use --upgrade=NONE instead.",
9162 &opt_no_dd_upgrade, &opt_no_dd_upgrade, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
9163 nullptr, 0, nullptr},
9164 {"validate-config", 0,
9165 "Validate the server configuration specified by the user.",
9166 &opt_validate_config, &opt_validate_config, nullptr, GET_BOOL, NO_ARG, 0,
9167 0, 0, nullptr, 0, nullptr},
9168 {"core-file", OPT_WANT_CORE, "Write core on errors.", 0, 0, nullptr,
9169 GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9170 {"coredumper", OPT_COREDUMPER,
9171 "Use coredumper library to generate coredumps. Specify a path for "
9172 "coredump "
9173 "otherwise it will be generated on datadir",
9174 &opt_libcoredumper_path, &opt_libcoredumper_path, 0, GET_STR, OPT_ARG, 0,
9175 0, 0, 0, 0, 0},
9176 {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
9177 "Don't print a stack trace on failure.", 0, 0, nullptr, GET_NO_ARG, NO_ARG,
9178 0, 0, 0, nullptr, 0, nullptr},
9179 /* We must always support the next option to make scripts like mysqltest
9180 easier to do */
9181 {"gdb", 0, "Set up signals usable for debugging.", &opt_debugging,
9182 &opt_debugging, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9183 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
9184 0, nullptr, 0, nullptr}};
9185
9186 /**
9187 System variables are automatically command-line options (few
9188 exceptions are documented in sys_var.h), so don't need
9189 to be listed here.
9190 */
9191
9192 struct my_option my_long_options[] = {
9193 {"abort-slave-event-count", OPT_ABORT_SLAVE_EVENT_COUNT,
9194 "Option used by mysql-test for debugging and testing of replication."
9195 "This option is deprecated and will be removed in a future version. ",
9196 &abort_slave_event_count, &abort_slave_event_count, nullptr, GET_INT,
9197 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9198 {"allow-suspicious-udfs", 0,
9199 "Allows use of UDFs consisting of only one symbol xxx() "
9200 "without corresponding xxx_init() or xxx_deinit(). That also means "
9201 "that one can load any function from any library, for example exit() "
9202 "from libc.so",
9203 &opt_allow_suspicious_udfs, &opt_allow_suspicious_udfs, nullptr, GET_BOOL,
9204 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9205 {"ansi", 'a',
9206 "Use ANSI SQL syntax instead of MySQL syntax. This mode "
9207 "will also set transaction isolation level 'serializable'.",
9208 nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
9209 nullptr},
9210 /*
9211 Because Sys_var_bit does not support command-line options, we need to
9212 explicitly add one for --autocommit
9213 */
9214 {"autocommit", 0, "Set default value for autocommit (0 or 1)",
9215 &opt_autocommit, &opt_autocommit, nullptr, GET_BOOL, OPT_ARG, 1, 0, 0,
9216 &source_autocommit, /* arg_source, to be copied to Sys_var */
9217 0, nullptr},
9218 {"binlog-do-db", OPT_BINLOG_DO_DB,
9219 "Include only updates to the specified database when writing the "
9220 "binary log.",
9221 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9222 nullptr},
9223 {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
9224 "Exclude updates to the specified database when writing the binary "
9225 "log.",
9226 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9227 nullptr},
9228 {"character-set-client-handshake", 0,
9229 "Don't ignore client side character set value sent during handshake.",
9230 &opt_character_set_client_handshake, &opt_character_set_client_handshake,
9231 nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
9232 {"character-set-filesystem", 0, "Set the filesystem character set.",
9233 &character_set_filesystem_name, &character_set_filesystem_name, nullptr,
9234 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9235 {"character-set-server", 'C', "Set the default character set.",
9236 &default_character_set_name, &default_character_set_name, nullptr, GET_STR,
9237 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9238 {"chroot", 'r', "Chroot mysqld daemon during startup.", &mysqld_chroot,
9239 &mysqld_chroot, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9240 nullptr},
9241 {"collation-server", 0, "Set the default collation.",
9242 &default_collation_name, &default_collation_name, nullptr, GET_STR,
9243 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9244 {"console", OPT_CONSOLE,
9245 "Write error output on screen; don't remove the console window on "
9246 "windows.",
9247 &opt_console, &opt_console, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
9248 nullptr},
9249 /* default-storage-engine should have "MyISAM" as def_value. Instead
9250 of initializing it here it is done in init_common_variables() due
9251 to a compiler bug in Sun Studio compiler. */
9252 {"default-storage-engine", 0, "The default storage engine for new tables",
9253 &default_storage_engine, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9254 nullptr, 0, nullptr},
9255 {"default-tmp-storage-engine", 0,
9256 "The default storage engine for new explicit temporary tables",
9257 &default_tmp_storage_engine, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
9258 0, nullptr, 0, nullptr},
9259 {"default-time-zone", 0, "Set the default time zone.", &default_tz_name,
9260 &default_tz_name, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9261 nullptr},
9262 {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
9263 "Option used by mysql-test for debugging and testing of replication."
9264 "This option is deprecated and will be removed in a future version.",
9265 &disconnect_slave_event_count, &disconnect_slave_event_count, nullptr,
9266 GET_INT, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9267 {"exit-info", 'T', "Used for debugging. Use at your own risk.", nullptr,
9268 nullptr, nullptr, GET_LONG, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
9269
9270 {"external-locking", 0,
9271 "Use system (external) locking (disabled by "
9272 "default). With this option enabled you can run myisamchk to test "
9273 "(not repair) tables while the MySQL server is running. Disable with "
9274 "--skip-external-locking.",
9275 &opt_external_locking, &opt_external_locking, nullptr, GET_BOOL, NO_ARG, 0,
9276 0, 0, nullptr, 0, nullptr},
9277 #if defined(HAVE_LINUX_LARGE_PAGES) || defined(HAVE_SOLARIS_LARGE_PAGES)
9278 {"super-large-pages", 0, "Enable support for super large pages.",
9279 &opt_super_large_pages, &opt_super_large_pages, nullptr, GET_BOOL, OPT_ARG,
9280 0, 0, 1, nullptr, 1, nullptr},
9281 #endif
9282 {"language", 'L',
9283 "Client error messages in given language. May be given as a full path. "
9284 "Deprecated. Use --lc-messages-dir instead.",
9285 &lc_messages_dir_ptr, &lc_messages_dir_ptr, nullptr, GET_STR, REQUIRED_ARG,
9286 0, 0, 0, nullptr, 0, nullptr},
9287 {"lc-messages", 0, "Set the language used for the error messages.",
9288 &lc_messages, &lc_messages, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9289 nullptr, 0, nullptr},
9290 {"lc-time-names", 0,
9291 "Set the language used for the month names and the days of the week.",
9292 &lc_time_names_name, &lc_time_names_name, nullptr, GET_STR, REQUIRED_ARG,
9293 0, 0, 0, nullptr, 0, nullptr},
9294 {"log-bin", OPT_BIN_LOG,
9295 "Configures the name prefix to use for binary log files. If the --log-bin "
9296 "option is not supplied, the name prefix defaults to \"binlog\". If the "
9297 "--log-bin option is supplied without argument, the name prefix defaults "
9298 "to \"HOSTNAME-bin\", where HOSTNAME is the machine's hostname. To set a "
9299 "different name prefix for binary log files, use --log-bin=name. To "
9300 "disable "
9301 "binary logging, use the --skip-log-bin or --disable-log-bin option.",
9302 &opt_bin_logname, &opt_bin_logname, nullptr, GET_STR_ALLOC, OPT_ARG, 0, 0,
9303 0, nullptr, 0, nullptr},
9304 {"log-bin-index", 0, "File that holds the names for binary log files.",
9305 &opt_binlog_index_name, &opt_binlog_index_name, nullptr, GET_STR,
9306 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9307 {"relay-log-index", 0, "File that holds the names for relay log files.",
9308 &opt_relaylog_index_name, &opt_relaylog_index_name, nullptr, GET_STR,
9309 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9310 {"log-isam", OPT_ISAM_LOG, "Log all MyISAM changes to file.",
9311 &myisam_log_filename, &myisam_log_filename, nullptr, GET_STR, OPT_ARG, 0,
9312 0, 0, nullptr, 0, nullptr},
9313 {"log-short-format", 0,
9314 "Don't log extra information to update and slow-query logs.",
9315 &opt_short_log_format, &opt_short_log_format, nullptr, GET_BOOL, NO_ARG, 0,
9316 0, 0, nullptr, 0, nullptr},
9317 {"log-tc", 0,
9318 "Path to transaction coordinator log (used for transactions that affect "
9319 "more than one storage engine, when binary log is disabled).",
9320 &opt_tc_log_file, &opt_tc_log_file, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
9321 0, nullptr, 0, nullptr},
9322 {"log-tc-size", 0, "Size of transaction coordinator log.", &opt_tc_log_size,
9323 &opt_tc_log_size, nullptr, GET_ULONG, REQUIRED_ARG,
9324 TC_LOG_MIN_PAGES *my_getpagesize(), TC_LOG_MIN_PAGES *my_getpagesize(),
9325 ULONG_MAX, nullptr, my_getpagesize(), nullptr},
9326 {"master-info-file", OPT_MASTER_INFO_FILE,
9327 "The path and filename where the replication receiver thread stores "
9328 "connection configuration and positions, in case "
9329 "--master-info-repository=FILE. "
9330 "This option is deprecated and will be removed in a future version.",
9331 &master_info_file, &master_info_file, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
9332 0, nullptr, 0, nullptr},
9333 {"master-retry-count", OPT_MASTER_RETRY_COUNT,
9334 "The number of times this replica will attempt to connect to a source "
9335 "before giving up. "
9336 "This option is deprecated and will be removed in a future version. "
9337 "Use 'CHANGE REPLICATION SOURCE TO SOURCE_RETRY_COUNT = <num>' instead.",
9338 &master_retry_count, &master_retry_count, nullptr, GET_ULONG, REQUIRED_ARG,
9339 3600 * 24, 0, 0, nullptr, 0, nullptr},
9340 {"max-binlog-dump-events", 0,
9341 "Option used by mysql-test for debugging and testing of replication.",
9342 &max_binlog_dump_events, &max_binlog_dump_events, nullptr, GET_INT,
9343 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9344 {"memlock", 0, "Lock mysqld in memory.", &locked_in_memory,
9345 &locked_in_memory, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
9346 nullptr},
9347 {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
9348 "Enable old-style user limits (before 5.0.3, user resources were counted "
9349 "for each user + host vs. per account). "
9350 "This option is deprecated and will be removed in a future version.",
9351 &opt_old_style_user_limits, &opt_old_style_user_limits, nullptr, GET_BOOL,
9352 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9353 {"port-open-timeout", 0,
9354 "Maximum time in seconds to wait for the port to become free. "
9355 "(Default: No wait).",
9356 &mysqld_port_timeout, &mysqld_port_timeout, nullptr, GET_UINT,
9357 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9358 {"replicate-do-db", OPT_REPLICATE_DO_DB,
9359 "Make replication applier threads apply only changes to the specified "
9360 "database. "
9361 "To specify more than one database, use the directive multiple times, "
9362 "once for each database. Note that this will only work if you do not use "
9363 "cross-database queries such as UPDATE some_db.some_table SET foo='bar' "
9364 "while having selected a different or no database. If you need cross "
9365 "database updates to work, make sure you have 3.23.28 or later, and use "
9366 "replicate-wild-do-table=db_name.%.",
9367 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9368 nullptr},
9369 {"replicate-do-table", OPT_REPLICATE_DO_TABLE,
9370 "Make replication applier threads apply only changes to the specified "
9371 "table. "
9372 "To specify more than one table, use the directive multiple times, once "
9373 "for each table. This will work for cross-database updates, in contrast "
9374 "to replicate-do-db.",
9375 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9376 nullptr},
9377 {"replica-enable-event", OPT_REPLICA_ENABLE_EVENT,
9378 "Tells the replication applier thread to enable the events that match "
9379 "the specified wildcard pattern without setting it as SLAVESIDE_DISABLED. "
9380 "To specify more than one event, use the directive multiple times, once "
9381 "for each event. This will work for cross-database events. Example: "
9382 "replica-enable-event=foo%.bar% will enable the events in all "
9383 "databases on replica server that start with 'foo' and whose event names "
9384 "start with 'bar'. It is recommended to use this feature only for "
9385 "read-only events to avoid data inconsistency.",
9386 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9387 nullptr},
9388 {"replicate-ignore-db", OPT_REPLICATE_IGNORE_DB,
9389 "Make replication applier threads skip changes to the specified "
9390 "database. "
9391 "To specify more than one database to ignore, use this option multiple "
9392 "times, once for each database. If there are statements that update "
9393 "multiple databases, this will work correctly only when the source "
9394 "server uses binlog_format=ROW.",
9395 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9396 nullptr},
9397 {"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
9398 "Make replication applier threads skip changes to the specified table."
9399 "To ignore more than one table, use the option multiple times, once for "
9400 "each table. If there are statements that update multiple tables, this "
9401 "will work correctly only when the source server uses binlog_format=ROW.",
9402 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9403 nullptr},
9404 {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
9405 "Make replication applier threads rename a database, so changes in one "
9406 "database on the source will be applied in another database on this "
9407 "replica. Example: "
9408 "replicate-rewrite-db=source_db_name->replica_db_name.",
9409 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9410 nullptr},
9411 {"replicate-same-server-id", 0,
9412 "In replication, if set to 1, do not skip events having our server id. "
9413 "Default value is 0 (to break infinite loops in circular replication). "
9414 "Can't be set to 1 if --log-replica-updates is used.",
9415 &replicate_same_server_id, &replicate_same_server_id, nullptr, GET_BOOL,
9416 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9417 {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE,
9418 "Make replication applier threads apply changes only in tables that "
9419 "match the specified wildcard pattern. To specify more than one pattern, "
9420 "use the option multiple times, once for each pattern. If there are "
9421 "statements that update both tables that are included and excluded by "
9422 "the pattern, this will only work correctly when the source server uses "
9423 "binlog_format=ROW. "
9424 "Example: replicate-wild-do-table=foo%.bar% will "
9425 "replicate only updates to tables in all databases that start with foo "
9426 "and whose table names start with bar.",
9427 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9428 nullptr},
9429 {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE,
9430 "Make replication applier threads skip changes to tables that match "
9431 "the specified wildcard pattern. To specify more than one pattern, use "
9432 "the option multiple times, once for each pattern. If there are "
9433 "statements that update both tables that are included and tables that "
9434 "are excluded by the pattern, this will only work correctly when the "
9435 "source server uses binlog_format=ROW. "
9436 "Example: when using replicate-wild-ignore-table=foo%.bar%, "
9437 "the applier thread will not apply updates to tables in databases that "
9438 "start with foo and whose table names start with bar.",
9439 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9440 nullptr},
9441 {"safe-user-create", 0,
9442 "Don't allow new user creation by the user who has no write privileges to "
9443 "the mysql.user table.",
9444 &opt_safe_user_create, &opt_safe_user_create, nullptr, GET_BOOL, NO_ARG, 0,
9445 0, 0, nullptr, 0, nullptr},
9446 {"show-replica-auth-info", 0,
9447 "Include user and password in SHOW REPLICAS statements.",
9448 &opt_show_replica_auth_info, &opt_show_replica_auth_info, nullptr,
9449 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9450 {"show-slave-auth-info", OPT_SHOW_SLAVE_AUTH_INFO_DEPRECATED,
9451 "This option is deprecated and will be removed in a future version. "
9452 "Use show-replica-auth-info instead.",
9453 &opt_show_replica_auth_info, &opt_show_replica_auth_info, nullptr,
9454 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9455 {"skip-host-cache", OPT_SKIP_HOST_CACHE_DEPRECATED,
9456 "Don't cache host names.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG,
9457 0, 0, 0, nullptr, 0, nullptr},
9458 {"skip-new", OPT_SKIP_NEW, "Don't use new, possibly wrong routines.",
9459 nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
9460 nullptr},
9461 #if defined(_WIN32)
9462 {"slow-start-timeout", 0,
9463 "Maximum number of milliseconds that the service control manager should "
9464 "wait "
9465 "before trying to kill the windows service during startup"
9466 "(Default: 15000).",
9467 &slow_start_timeout, &slow_start_timeout, 0, GET_ULONG, REQUIRED_ARG,
9468 15000, 0, 0, 0, 0, 0},
9469 #endif
9470 {"sporadic-binlog-dump-fail", 0,
9471 "Option used by mysql-test for debugging and testing of replication.",
9472 &opt_sporadic_binlog_dump_fail, &opt_sporadic_binlog_dump_fail, nullptr,
9473 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9474 {"ssl", OPT_USE_SSL,
9475 "Enable SSL for connection (automatically enabled with other flags).",
9476 &opt_use_ssl, &opt_use_ssl, nullptr, GET_BOOL, OPT_ARG, 1, 0, 0, nullptr,
9477 0, nullptr},
9478 {"admin-ssl", OPT_USE_ADMIN_SSL,
9479 "Enable SSL for admin interface (automatically enabled with other flags).",
9480 &opt_use_admin_ssl, &opt_use_admin_ssl, nullptr, GET_BOOL, OPT_ARG, 1, 0,
9481 0, nullptr, 0, nullptr},
9482 #ifdef _WIN32
9483 {"standalone", 0, "Dummy option to start as a standalone program (NT).", 0,
9484 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
9485 {"no-monitor", 0, "Disable monitor process.", &opt_no_monitor,
9486 &opt_no_monitor, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
9487 #endif
9488 {"symbolic-links", 's',
9489 "Enable symbolic link support (deprecated and will be removed in a future"
9490 " release).",
9491 &my_enable_symlinks, &my_enable_symlinks, nullptr, GET_BOOL, NO_ARG, 0, 0,
9492 0, nullptr, 0, nullptr},
9493 {"sysdate-is-now", 0,
9494 "Non-default option to alias SYSDATE() to NOW() to make it "
9495 "safe-replicable. "
9496 "Since 5.0, SYSDATE() returns a `dynamic' value different for different "
9497 "invocations, even within the same statement.",
9498 &global_system_variables.sysdate_is_now, nullptr, nullptr, GET_BOOL,
9499 NO_ARG, 0, 0, 1, nullptr, 1, nullptr},
9500 {"tc-heuristic-recover", 0,
9501 "Decision to use in heuristic recover process. Possible values are OFF, "
9502 "COMMIT or ROLLBACK.",
9503 &tc_heuristic_recover, &tc_heuristic_recover,
9504 &tc_heuristic_recover_typelib, GET_ENUM, REQUIRED_ARG,
9505 TC_HEURISTIC_NOT_USED, 0, 0, nullptr, 0, nullptr},
9506 #if defined(ENABLED_DEBUG_SYNC)
9507 {"debug-sync-timeout", OPT_DEBUG_SYNC_TIMEOUT,
9508 "Enable the debug sync facility "
9509 "and optionally specify a default wait timeout in seconds. "
9510 "A zero value keeps the facility disabled.",
9511 &opt_debug_sync_timeout, nullptr, nullptr, GET_UINT, OPT_ARG, 0, 0,
9512 UINT_MAX, nullptr, 0, nullptr},
9513 #endif /* defined(ENABLED_DEBUG_SYNC) */
9514 {"transaction-isolation", 0, "Default transaction isolation level.",
9515 &global_system_variables.transaction_isolation,
9516 &global_system_variables.transaction_isolation, &tx_isolation_typelib,
9517 GET_ENUM, REQUIRED_ARG, ISO_REPEATABLE_READ, 0, 0, nullptr, 0, nullptr},
9518 {"transaction-read-only", 0,
9519 "Default transaction access mode. "
9520 "True if transactions are read-only.",
9521 &global_system_variables.transaction_read_only,
9522 &global_system_variables.transaction_read_only, nullptr, GET_BOOL, OPT_ARG,
9523 0, 0, 0, nullptr, 0, nullptr},
9524 {"user", 'u', "Run mysqld daemon as user.", nullptr, nullptr, nullptr,
9525 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9526 {"early-plugin-load", OPT_EARLY_PLUGIN_LOAD,
9527 "Optional semicolon-separated list of plugins to load before storage "
9528 "engine "
9529 "initialization, where each plugin is identified as name=library, where "
9530 "name is the plugin name and library is the plugin library in plugin_dir.",
9531 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9532 nullptr},
9533 {"plugin-load", OPT_PLUGIN_LOAD,
9534 "Optional semicolon-separated list of plugins to load, where each plugin "
9535 "is "
9536 "identified as name=library, where name is the plugin name and library "
9537 "is the plugin library in plugin_dir.",
9538 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9539 nullptr},
9540 {"plugin-load-add", OPT_PLUGIN_LOAD_ADD,
9541 "Optional semicolon-separated list of plugins to load, where each plugin "
9542 "is "
9543 "identified as name=library, where name is the plugin name and library "
9544 "is the plugin library in plugin_dir. This option adds to the list "
9545 "specified by --plugin-load in an incremental way. "
9546 "Multiple --plugin-load-add are supported.",
9547 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
9548 nullptr},
9549
9550 {"innodb", OPT_SKIP_INNODB,
9551 "Deprecated option. Provided for backward compatibility only. "
9552 "The option has no effect on the server behaviour. InnoDB is always "
9553 "enabled. "
9554 "The option will be removed in a future release.",
9555 nullptr, nullptr, nullptr, GET_BOOL, OPT_ARG, 0, 0, 0, nullptr, 0,
9556 nullptr},
9557
9558 {"upgrade", 0,
9559 "Set server upgrade mode. NONE to abort server if automatic upgrade of "
9560 "the server is needed; MINIMAL to start the server, but skip upgrade "
9561 "steps that are not absolutely necessary; AUTO (default) to upgrade the "
9562 "server if required; FORCE to force upgrade server.",
9563 &opt_upgrade_mode, &opt_upgrade_mode, &upgrade_mode_typelib, GET_ENUM,
9564 REQUIRED_ARG, UPGRADE_AUTO, 0, 0, nullptr, 0, nullptr},
9565
9566 {"utility_user", 0,
9567 "Specifies a MySQL user that will be added to the "
9568 "internal list of users and recognized as the utility user.",
9569 &utility_user, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
9570 {"utility_user_password", 0,
9571 "Specifies the password required for the "
9572 "utility user.",
9573 &utility_user_password, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
9574 {"utility_user_privileges", 0,
9575 "Specifies the privileges that the utility "
9576 "user will have in a comma delimited list. See the manual for a complete "
9577 "list of privileges.",
9578 &utility_user_privileges, 0, &utility_user_privileges_typelib, GET_SET,
9579 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
9580 {"utility_user_dynamic_privileges", 0,
9581 "Specifies the dynamic privileges that the utility "
9582 "user will have in a comma delimited list. See the manual for a complete "
9583 "list of privileges.",
9584 &utility_user_dynamic_privileges, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
9585 0, 0},
9586 {"utility_user_schema_access", 0,
9587 "Specifies the schemas that the utility "
9588 "user has access to in a comma delimited list.",
9589 &utility_user_schema_access, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
9590 0},
9591
9592 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
9593 0, nullptr, 0, nullptr}};
9594
9595 110009 static int show_queries(THD *thd, SHOW_VAR *var, char *) {
9596 110009 var->type = SHOW_LONGLONG;
9597 110009 var->value = (char *)&thd->query_id;
9598 110009 return 0;
9599 }
9600
9601 57555 static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff) {
9602 57555 var->type = SHOW_MY_BOOL;
9603 57555 var->value = buff;
9604 57555 *((bool *)buff) = thd->get_protocol()->get_compression();
9605 57555 return 0;
9606 }
9607
9608 57555 static int show_net_compression_algorithm(THD *thd, SHOW_VAR *var, char *buff) {
9609 57555 const char *s = thd->get_protocol()->get_compression_algorithm();
9610 57555 var->type = SHOW_CHAR;
9611 57555 var->value = buff;
9612
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 57470 times.
57555 sprintf(buff, "%s", (s ? s : ""));
9613 57555 return 0;
9614 }
9615
9616 57555 static int show_net_compression_level(THD *thd, SHOW_VAR *var, char *buff) {
9617 57555 var->type = SHOW_INT;
9618 57555 var->value = buff;
9619 57555 unsigned int *value = reinterpret_cast<unsigned int *>(buff);
9620 57555 *value = thd->get_protocol()->get_compression_level();
9621 57555 return 0;
9622 }
9623
9624 109342 static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) {
9625 109342 var->type = SHOW_LONGLONG;
9626 109342 var->value = buff;
9627 109342 *((longlong *)buff) =
9628 109342 (longlong)(thd->query_start_in_secs() - server_start_time);
9629 109342 return 0;
9630 }
9631
9632 109346 static int show_max_used_connections_time(THD *thd, SHOW_VAR *var, char *buff) {
9633 MYSQL_TIME max_used_connections_time;
9634 109346 var->type = SHOW_CHAR;
9635 109346 var->value = buff;
9636
1/2
✓ Branch 0 taken 109346 times.
✗ Branch 1 not taken.
109346 thd->variables.time_zone->gmt_sec_to_TIME(
9637 &max_used_connections_time,
9638 Connection_handler_manager::max_used_connections_time);
9639
1/2
✓ Branch 0 taken 109346 times.
✗ Branch 1 not taken.
109346 my_datetime_to_str(max_used_connections_time, buff, 0);
9640 109346 return 0;
9641 }
9642
9643 109342 static int show_num_thread_running(THD *, SHOW_VAR *var, char *buff) {
9644 109342 var->type = SHOW_LONGLONG;
9645 109342 var->value = buff;
9646 109342 long long *value = reinterpret_cast<long long *>(buff);
9647 109342 *value = static_cast<long long>(
9648 109342 Global_THD_manager::get_instance()->get_num_thread_running());
9649 109342 return 0;
9650 }
9651
9652 109342 static int show_num_thread_created(THD *, SHOW_VAR *var, char *buff) {
9653 109342 var->type = SHOW_LONG;
9654 109342 var->value = buff;
9655 109342 long *value = reinterpret_cast<long *>(buff);
9656 109342 *value = static_cast<long>(
9657 109342 Global_THD_manager::get_instance()->get_num_thread_created());
9658 109342 return 0;
9659 }
9660
9661 109351 static int show_thread_id_count(THD *, SHOW_VAR *var, char *buff) {
9662 109351 var->type = SHOW_LONG;
9663 109351 var->value = buff;
9664 109351 long *value = reinterpret_cast<long *>(buff);
9665 109351 *value = static_cast<long>(
9666 109351 Global_THD_manager::get_instance()->get_thread_id() - 1);
9667 109351 return 0;
9668 }
9669
9670 109351 static int show_aborted_connects(THD *, SHOW_VAR *var, char *buff) {
9671 109351 var->type = SHOW_LONG;
9672 109351 var->value = buff;
9673 109351 long *value = reinterpret_cast<long *>(buff);
9674 109351 *value = static_cast<long>(
9675 109351 Connection_handler_manager::get_instance()->aborted_connects());
9676 109351 return 0;
9677 }
9678
9679 109351 static int show_acl_cache_items_count(THD *, SHOW_VAR *var, char *buff) {
9680 109351 var->type = SHOW_LONG;
9681 109351 var->value = buff;
9682 109351 long *value = reinterpret_cast<long *>(buff);
9683 109351 *value = static_cast<long>(get_global_acl_cache_size());
9684 109351 return 0;
9685 }
9686
9687 109351 static int show_connection_errors_max_connection(THD *, SHOW_VAR *var,
9688 char *buff) {
9689 109351 var->type = SHOW_LONG;
9690 109351 var->value = buff;
9691 109351 long *value = reinterpret_cast<long *>(buff);
9692 109351 *value = static_cast<long>(Connection_handler_manager::get_instance()
9693 109351 ->connection_errors_max_connection());
9694 109351 return 0;
9695 }
9696
9697 109351 static int show_connection_errors_query_block(THD *, SHOW_VAR *var,
9698 char *buff) {
9699 109351 var->type = SHOW_LONG;
9700 109351 var->value = buff;
9701 109351 long *value = reinterpret_cast<long *>(buff);
9702 109351 *value = static_cast<long>(get_connection_errors_query_block());
9703 109351 return 0;
9704 }
9705
9706 109351 static int show_connection_errors_accept(THD *, SHOW_VAR *var, char *buff) {
9707 109351 var->type = SHOW_LONG;
9708 109351 var->value = buff;
9709 109351 long *value = reinterpret_cast<long *>(buff);
9710 109351 *value = static_cast<long>(get_connection_errors_accept());
9711 109351 return 0;
9712 }
9713
9714 109351 static int show_connection_errors_tcpwrap(THD *, SHOW_VAR *var, char *buff) {
9715 109351 var->type = SHOW_LONG;
9716 109351 var->value = buff;
9717 109351 long *value = reinterpret_cast<long *>(buff);
9718 109351 *value = static_cast<long>(get_connection_errors_tcpwrap());
9719 109351 return 0;
9720 }
9721
9722 #ifdef ENABLED_PROFILING
9723 109342 static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) {
9724 109342 var->type = SHOW_LONGLONG;
9725 109342 var->value = buff;
9726 109342 *((longlong *)buff) =
9727 109342 (longlong)(thd->query_start_in_secs() - flush_status_time);
9728 109342 return 0;
9729 }
9730 #endif
9731
9732 #ifndef NDEBUG
9733 218684 static int show_replica_rows_last_search_algorithm_used(THD *, SHOW_VAR *var,
9734 char *buff) {
9735 218684 uint res = replica_rows_last_search_algorithm_used;
9736 218684 const char *s =
9737 ((res == Rows_log_event::ROW_LOOKUP_TABLE_SCAN)
9738
2/2
✓ Branch 0 taken 218526 times.
✓ Branch 1 taken 158 times.
437210 ? "TABLE_SCAN"
9739
2/2
✓ Branch 0 taken 1340 times.
✓ Branch 1 taken 217186 times.
218526 : ((res == Rows_log_event::ROW_LOOKUP_HASH_SCAN) ? "HASH_SCAN"
9740 : "INDEX_SCAN"));
9741
9742 218684 var->type = SHOW_CHAR;
9743 218684 var->value = buff;
9744 218684 sprintf(buff, "%s", s);
9745
9746 218684 return 0;
9747 }
9748
9749 109342 static int show_ongoing_automatic_gtid_violating_transaction_count(
9750 THD *, SHOW_VAR *var, char *buf) {
9751 109342 var->type = SHOW_CHAR;
9752 109342 var->value = buf;
9753 109342 sprintf(buf, "%d",
9754 gtid_state->get_automatic_gtid_violating_transaction_count());
9755 109342 return 0;
9756 }
9757
9758 109342 static int show_ongoing_anonymous_gtid_violating_transaction_count(
9759 THD *, SHOW_VAR *var, char *buf) {
9760 109342 var->type = SHOW_CHAR;
9761 109342 var->value = buf;
9762 109342 sprintf(buf, "%d",
9763 gtid_state->get_anonymous_gtid_violating_transaction_count());
9764 109342 return 0;
9765 }
9766
9767 #endif
9768
9769 109342 static int show_ongoing_anonymous_transaction_count(THD *, SHOW_VAR *var,
9770 char *buf) {
9771 109342 var->type = SHOW_CHAR;
9772 109342 var->value = buf;
9773 109342 sprintf(buf, "%d", gtid_state->get_anonymous_ownership_count());
9774 109342 return 0;
9775 }
9776
9777 110009 static int show_open_tables(THD *, SHOW_VAR *var, char *buff) {
9778 110009 var->type = SHOW_LONG;
9779 110009 var->value = buff;
9780 110009 *((long *)buff) = (long)table_cache_manager.cached_tables();
9781 110009 return 0;
9782 }
9783
9784 109342 static int show_prepared_stmt_count(THD *, SHOW_VAR *var, char *buff) {
9785 109342 var->type = SHOW_LONG;
9786 109342 var->value = buff;
9787 109342 mysql_mutex_lock(&LOCK_prepared_stmt_count);
9788 109342 *((long *)buff) = (long)prepared_stmt_count;
9789 109342 mysql_mutex_unlock(&LOCK_prepared_stmt_count);
9790 109342 return 0;
9791 }
9792
9793 109351 static int show_global_mem_counter(THD *, SHOW_VAR *var, char *buff) {
9794 109351 var->type = SHOW_LONGLONG;
9795 109351 var->value = buff;
9796 109351 MUTEX_LOCK(lock, &LOCK_global_conn_mem_limit);
9797 109351 *((longlong *)buff) = (longlong)global_conn_mem_counter;
9798 218702 return 0;
9799 109351 }
9800
9801 109342 static int show_table_definitions(THD *, SHOW_VAR *var, char *buff) {
9802 109342 var->type = SHOW_LONG;
9803 109342 var->value = buff;
9804 109342 *((long *)buff) = (long)cached_table_definitions();
9805 109342 return 0;
9806 }
9807
9808 /*
9809 Functions relying on SSL
9810 Note: In the show_ssl_* functions, we need to check if we have a
9811 valid vio-object since this isn't always true, specifically
9812 when session_status or global_status is requested from
9813 inside an Event.
9814 */
9815 110009 static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *) {
9816 110009 SSL_handle ssl = thd->get_ssl();
9817 110009 var->type = SHOW_CHAR;
9818
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9819 194 var->value = const_cast<char *>(SSL_get_version(ssl));
9820 else
9821 109815 var->value = const_cast<char *>("");
9822 110009 return 0;
9823 }
9824
9825 110009 static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) {
9826 110009 SSL_handle ssl = thd->get_ssl();
9827 110009 var->type = SHOW_LONG;
9828 110009 var->value = buff;
9829
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9830 194 *((long *)buff) = (long)SSL_session_reused(ssl);
9831 else
9832 109815 *((long *)buff) = 0;
9833 110009 return 0;
9834 }
9835
9836 110009 static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) {
9837 110009 SSL_handle ssl = thd->get_ssl();
9838 110009 var->type = SHOW_LONG;
9839 110009 var->value = buff;
9840
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9841 194 *((long *)buff) = (long)SSL_get_default_timeout(ssl);
9842 else
9843 109815 *((long *)buff) = 0;
9844 110009 return 0;
9845 }
9846
9847 110009 static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) {
9848 110009 SSL_handle ssl = thd->get_ssl();
9849 110009 var->type = SHOW_LONG;
9850 110009 var->value = buff;
9851
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9852 194 *((long *)buff) = (long)SSL_get_verify_mode(ssl);
9853 else
9854 109815 *((long *)buff) = 0;
9855 110009 return 0;
9856 }
9857
9858 110009 static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) {
9859 110009 SSL_handle ssl = thd->get_ssl();
9860 110009 var->type = SHOW_LONG;
9861 110009 var->value = buff;
9862
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9863 194 *((long *)buff) = (long)SSL_get_verify_depth(ssl);
9864 else
9865 109815 *((long *)buff) = 0;
9866 110009 return 0;
9867 }
9868
9869 110009 static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *) {
9870 110009 SSL_handle ssl = thd->get_ssl();
9871 110009 var->type = SHOW_CHAR;
9872
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl)
9873 194 var->value = const_cast<char *>(SSL_get_cipher(ssl));
9874 else
9875 109815 var->value = const_cast<char *>("");
9876 110009 return 0;
9877 }
9878
9879 110009 static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) {
9880 110009 SSL_handle ssl = thd->get_ssl();
9881 110009 var->type = SHOW_CHAR;
9882 110009 var->value = buff;
9883
2/2
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 109815 times.
110009 if (ssl) {
9884 int i;
9885 const char *p;
9886 194 char *end = buff + SHOW_VAR_FUNC_BUFF_SIZE;
9887
5/6
✓ Branch 0 taken 5905 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 5905 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5905 times.
✓ Branch 5 taken 194 times.
6099 for (i = 0; (p = SSL_get_cipher_list(ssl, i)) && buff < end; i++) {
9888 5905 buff = my_stpnmov(buff, p, end - buff - 1);
9889 5905 *buff++ = ':';
9890 }
9891
1/2
✓ Branch 0 taken 194 times.
✗ Branch 1 not taken.
194 if (i) buff--;
9892 }
9893 110009 *buff = 0;
9894 110009 return 0;
9895 }
9896
9897 #ifdef HAVE_POOL_OF_THREADS
9898 109342 static int show_threadpool_idle_threads(THD *thd [[maybe_unused]],
9899 SHOW_VAR *var, char *buff) {
9900 109342 var->type = SHOW_INT;
9901 109342 var->value = buff;
9902 109342 *(int *)buff = tp_get_idle_thread_count();
9903 109342 return 0;
9904 }
9905 #endif
9906
9907 218684 static int show_replica_open_temp_tables(THD *, SHOW_VAR *var, char *buf) {
9908 218684 var->type = SHOW_INT;
9909 218684 var->value = buf;
9910 218684 *((int *)buf) = atomic_replica_open_temp_tables;
9911 218684 return 0;
9912 }
9913 5 bool validate_libcoredumper_path(char *libcoredumper_path) {
9914 /* validate path */
9915
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
5 if (!is_valid_log_name(
9916 libcoredumper_path,
9917 strlen(libcoredumper_path))) { // filename contain .cnf or .ini on it
9918
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Variable --coredumper cannot be set to value %s",
9919 libcoredumper_path);
9920 1 return false;
9921 }
9922 char libcoredumper_dir[FN_REFLEN];
9923 size_t libcoredumper_dir_length;
9924 4 size_t opt_libcoredumper_path_length = strlen(libcoredumper_path);
9925
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 (void)dirname_part(libcoredumper_dir, libcoredumper_path,
9926 &libcoredumper_dir_length);
9927
9928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!libcoredumper_dir_length) {
9929 sql_print_error("Error processing --coredumper path: %s",
9930 libcoredumper_path);
9931 return false;
9932 }
9933 4 size_t libcoredumper_file_length =
9934 4 opt_libcoredumper_path_length - libcoredumper_dir_length;
9935
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (libcoredumper_file_length == 0) // path is a directory
9936 {
9937 1 libcoredumper_file_length = 19; // file is set to core.yyyymmddhhmmss
9938 } else {
9939 3 libcoredumper_file_length += 15; // file gets .yyyymmddhhmmss appended
9940 }
9941
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (opt_libcoredumper_path_length > FN_REFLEN) { // path is too long
9942
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Variable --coredumper set to a too long path");
9943 1 return false;
9944 }
9945
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (libcoredumper_file_length > FN_LEN) { // filename is too long
9946
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Variable --coredumper set to a too long filename");
9947 1 return false;
9948 }
9949
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (my_access(libcoredumper_dir, F_OK)) {
9950
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Directory specified at --coredumper: %s does not exist",
9951 libcoredumper_dir);
9952 1 return false;
9953 }
9954
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (my_access(libcoredumper_dir, (F_OK | W_OK))) {
9955
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Directory specified at --coredumper: %s is not writable",
9956 libcoredumper_dir);
9957 1 return false;
9958 }
9959 if (libcoredumper_dir_length ==
9960 strlen(libcoredumper_path)) { // only dirname was specified, append core
9961 // to libcoredumper_path
9962 strcat(libcoredumper_path, "core");
9963 }
9964 return true;
9965 }
9966
9967 109342 static int show_tls_library_version(THD *, SHOW_VAR *var, char *buff) {
9968 #if OPENSSL_VERSION_NUMBER <= 0x10100000L
9969 strncpy(buff, SSLeay_version(SSLEAY_VERSION), SHOW_VAR_FUNC_BUFF_SIZE);
9970 #else
9971 109342 strncpy(buff, OpenSSL_version(OPENSSL_VERSION), SHOW_VAR_FUNC_BUFF_SIZE);
9972 #endif
9973 109342 buff[SHOW_VAR_FUNC_BUFF_SIZE - 1] = 0;
9974 109342 var->type = SHOW_CHAR;
9975 109342 var->value = buff;
9976 109342 return 0;
9977 }
9978
9979 /*
9980 Variables shown by SHOW STATUS in alphabetical order
9981 */
9982 SHOW_VAR status_vars[] = {
9983 {"Aborted_clients", (char *)&aborted_threads, SHOW_LONG, SHOW_SCOPE_GLOBAL},
9984 {"Aborted_connects", (char *)&show_aborted_connects, SHOW_FUNC,
9985 SHOW_SCOPE_GLOBAL},
9986 {"Acl_cache_items_count", (char *)&show_acl_cache_items_count, SHOW_FUNC,
9987 SHOW_SCOPE_GLOBAL},
9988 #ifndef NDEBUG
9989 {"Ongoing_anonymous_gtid_violating_transaction_count",
9990 (char *)&show_ongoing_anonymous_gtid_violating_transaction_count,
9991 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
9992 #endif //! NDEBUG
9993 {"Ongoing_anonymous_transaction_count",
9994 (char *)&show_ongoing_anonymous_transaction_count, SHOW_FUNC,
9995 SHOW_SCOPE_GLOBAL},
9996 #ifndef NDEBUG
9997 {"Ongoing_automatic_gtid_violating_transaction_count",
9998 (char *)&show_ongoing_automatic_gtid_violating_transaction_count,
9999 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10000 #endif //! NDEBUG
10001 {"Binlog_cache_disk_use", (char *)&binlog_cache_disk_use, SHOW_LONG,
10002 SHOW_SCOPE_GLOBAL},
10003 {"Binlog_cache_use", (char *)&binlog_cache_use, SHOW_LONG,
10004 SHOW_SCOPE_GLOBAL},
10005 {"Binlog_stmt_cache_disk_use", (char *)&binlog_stmt_cache_disk_use,
10006 SHOW_LONG, SHOW_SCOPE_GLOBAL},
10007 {"Binlog_stmt_cache_use", (char *)&binlog_stmt_cache_use, SHOW_LONG,
10008 SHOW_SCOPE_GLOBAL},
10009 {"Bytes_received", (char *)offsetof(System_status_var, bytes_received),
10010 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10011 {"Bytes_sent", (char *)offsetof(System_status_var, bytes_sent),
10012 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10013 {"Com", (char *)com_status_vars, SHOW_ARRAY, SHOW_SCOPE_ALL},
10014 {"Com_stmt_reprepare",
10015 (char *)offsetof(System_status_var, com_stmt_reprepare), SHOW_LONG_STATUS,
10016 SHOW_SCOPE_ALL},
10017 {"Compression", (char *)&show_net_compression, SHOW_FUNC,
10018 SHOW_SCOPE_SESSION},
10019 {"Compression_algorithm", (char *)&show_net_compression_algorithm,
10020 SHOW_FUNC, SHOW_SCOPE_SESSION},
10021 {"Compression_level", (char *)&show_net_compression_level, SHOW_FUNC,
10022 SHOW_SCOPE_SESSION},
10023 {"Connections", (char *)&show_thread_id_count, SHOW_FUNC,
10024 SHOW_SCOPE_GLOBAL},
10025 {"Connection_errors_accept", (char *)&show_connection_errors_accept,
10026 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10027 {"Connection_errors_internal", (char *)&connection_errors_internal,
10028 SHOW_LONG, SHOW_SCOPE_GLOBAL},
10029 {"Connection_errors_max_connections",
10030 (char *)&show_connection_errors_max_connection, SHOW_FUNC,
10031 SHOW_SCOPE_GLOBAL},
10032 {"Connection_errors_peer_address", (char *)&connection_errors_peer_addr,
10033 SHOW_LONG, SHOW_SCOPE_GLOBAL},
10034 {"Connection_errors_select", (char *)&show_connection_errors_query_block,
10035 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10036 {"Connection_errors_tcpwrap", (char *)&show_connection_errors_tcpwrap,
10037 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10038 {"Created_tmp_disk_tables",
10039 (char *)offsetof(System_status_var, created_tmp_disk_tables),
10040 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10041 {"Created_tmp_files", (char *)&my_tmp_file_created, SHOW_LONG,
10042 SHOW_SCOPE_GLOBAL},
10043 {"Created_tmp_tables",
10044 (char *)offsetof(System_status_var, created_tmp_tables),
10045 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10046 {"Delayed_errors", (char *)&delayed_insert_errors, SHOW_LONG,
10047 SHOW_SCOPE_GLOBAL},
10048 {"Delayed_insert_threads", (char *)&delayed_insert_threads,
10049 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10050 {"Delayed_writes", (char *)&delayed_insert_writes, SHOW_LONG,
10051 SHOW_SCOPE_GLOBAL},
10052 {"Error_log_buffered_bytes", (char *)&log_sink_pfs_buffered_bytes,
10053 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10054 {"Error_log_buffered_events", (char *)&log_sink_pfs_buffered_events,
10055 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10056 {"Error_log_expired_events", (char *)&log_sink_pfs_expired_events,
10057 SHOW_LONG, SHOW_SCOPE_GLOBAL},
10058 {"Error_log_latest_write", (char *)&log_sink_pfs_latest_timestamp,
10059 SHOW_LONGLONG, SHOW_SCOPE_GLOBAL},
10060 {"Flush_commands", (char *)&refresh_version, SHOW_LONG_NOFLUSH,
10061 SHOW_SCOPE_GLOBAL},
10062 {"Global_connection_memory", (char *)&show_global_mem_counter, SHOW_FUNC,
10063 SHOW_SCOPE_GLOBAL},
10064 {"Handler_commit", (char *)offsetof(System_status_var, ha_commit_count),
10065 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10066 {"Handler_delete", (char *)offsetof(System_status_var, ha_delete_count),
10067 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10068 {"Handler_discover", (char *)offsetof(System_status_var, ha_discover_count),
10069 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10070 {"Handler_external_lock",
10071 (char *)offsetof(System_status_var, ha_external_lock_count),
10072 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10073 {"Handler_mrr_init",
10074 (char *)offsetof(System_status_var, ha_multi_range_read_init_count),
10075 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10076 {"Handler_prepare", (char *)offsetof(System_status_var, ha_prepare_count),
10077 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10078 {"Handler_read_first",
10079 (char *)offsetof(System_status_var, ha_read_first_count),
10080 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10081 {"Handler_read_key", (char *)offsetof(System_status_var, ha_read_key_count),
10082 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10083 {"Handler_read_last",
10084 (char *)offsetof(System_status_var, ha_read_last_count),
10085 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10086 {"Handler_read_next",
10087 (char *)offsetof(System_status_var, ha_read_next_count),
10088 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10089 {"Handler_read_prev",
10090 (char *)offsetof(System_status_var, ha_read_prev_count),
10091 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10092 {"Handler_read_rnd", (char *)offsetof(System_status_var, ha_read_rnd_count),
10093 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10094 {"Handler_read_rnd_next",
10095 (char *)offsetof(System_status_var, ha_read_rnd_next_count),
10096 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10097 {"Handler_rollback", (char *)offsetof(System_status_var, ha_rollback_count),
10098 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10099 {"Handler_savepoint",
10100 (char *)offsetof(System_status_var, ha_savepoint_count),
10101 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10102 {"Handler_savepoint_rollback",
10103 (char *)offsetof(System_status_var, ha_savepoint_rollback_count),
10104 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10105 {"Handler_update", (char *)offsetof(System_status_var, ha_update_count),
10106 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10107 {"Handler_write", (char *)offsetof(System_status_var, ha_write_count),
10108 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10109 {"Key_blocks_not_flushed",
10110 (char *)offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG,
10111 SHOW_SCOPE_GLOBAL},
10112 {"Key_blocks_unused", (char *)offsetof(KEY_CACHE, blocks_unused),
10113 SHOW_KEY_CACHE_LONG, SHOW_SCOPE_GLOBAL},
10114 {"Key_blocks_used", (char *)offsetof(KEY_CACHE, blocks_used),
10115 SHOW_KEY_CACHE_LONG, SHOW_SCOPE_GLOBAL},
10116 {"Key_read_requests", (char *)offsetof(KEY_CACHE, global_cache_r_requests),
10117 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
10118 {"Key_reads", (char *)offsetof(KEY_CACHE, global_cache_read),
10119 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
10120 {"Key_write_requests", (char *)offsetof(KEY_CACHE, global_cache_w_requests),
10121 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
10122 {"Key_writes", (char *)offsetof(KEY_CACHE, global_cache_write),
10123 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
10124 {"Last_query_cost", (char *)offsetof(System_status_var, last_query_cost),
10125 SHOW_DOUBLE_STATUS, SHOW_SCOPE_SESSION},
10126 {"Last_query_partial_plans",
10127 (char *)offsetof(System_status_var, last_query_partial_plans),
10128 SHOW_LONGLONG_STATUS, SHOW_SCOPE_SESSION},
10129 {"Locked_connects", (char *)&locked_account_connection_count, SHOW_LONG,
10130 SHOW_SCOPE_GLOBAL},
10131 {"Max_execution_time_exceeded",
10132 (char *)offsetof(System_status_var, max_execution_time_exceeded),
10133 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10134 {"Max_execution_time_set",
10135 (char *)offsetof(System_status_var, max_execution_time_set),
10136 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10137 {"Max_execution_time_set_failed",
10138 (char *)offsetof(System_status_var, max_execution_time_set_failed),
10139 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10140 {"Max_used_connections",
10141 (char *)&Connection_handler_manager::max_used_connections, SHOW_LONG,
10142 SHOW_SCOPE_GLOBAL},
10143 {"Max_used_connections_time", (char *)&show_max_used_connections_time,
10144 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10145 {"Net_buffer_length",
10146 (char *)offsetof(System_status_var, net_buffer_length),
10147 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10148 {"Not_flushed_delayed_rows", (char *)&delayed_rows_in_use,
10149 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10150 {"Open_files", (char *)&my_file_opened, SHOW_LONG_NOFLUSH,
10151 SHOW_SCOPE_GLOBAL},
10152 {"Open_streams", (char *)&my_stream_opened, SHOW_LONG_NOFLUSH,
10153 SHOW_SCOPE_GLOBAL},
10154 {"Open_table_definitions", (char *)&show_table_definitions, SHOW_FUNC,
10155 SHOW_SCOPE_GLOBAL},
10156 {"Open_tables", (char *)&show_open_tables, SHOW_FUNC, SHOW_SCOPE_ALL},
10157 {"Opened_files",
10158 const_cast<char *>(reinterpret_cast<const char *>(&my_file_total_opened)),
10159 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10160 {"Opened_tables", (char *)offsetof(System_status_var, opened_tables),
10161 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10162 {"Opened_table_definitions",
10163 (char *)offsetof(System_status_var, opened_shares), SHOW_LONGLONG_STATUS,
10164 SHOW_SCOPE_ALL},
10165 {"Prepared_stmt_count", (char *)&show_prepared_stmt_count, SHOW_FUNC,
10166 SHOW_SCOPE_GLOBAL},
10167 {"Replica_open_temp_tables", (char *)&show_replica_open_temp_tables,
10168 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10169 #ifndef NDEBUG
10170 {"Replica_rows_last_search_algorithm_used",
10171 (char *)&show_replica_rows_last_search_algorithm_used, SHOW_FUNC,
10172 SHOW_SCOPE_GLOBAL},
10173 #endif
10174 {"Queries", (char *)&show_queries, SHOW_FUNC, SHOW_SCOPE_ALL},
10175 {"Questions", (char *)offsetof(System_status_var, questions),
10176 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10177 {"Secondary_engine_execution_count",
10178 (char *)offsetof(System_status_var, secondary_engine_execution_count),
10179 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10180 {"Select_full_join",
10181 (char *)offsetof(System_status_var, select_full_join_count),
10182 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10183 {"Select_full_range_join",
10184 (char *)offsetof(System_status_var, select_full_range_join_count),
10185 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10186 {"Select_range", (char *)offsetof(System_status_var, select_range_count),
10187 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10188 {"Select_range_check",
10189 (char *)offsetof(System_status_var, select_range_check_count),
10190 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10191 {"Select_scan", (char *)offsetof(System_status_var, select_scan_count),
10192 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10193 {"Slave_open_temp_tables", (char *)&show_replica_open_temp_tables,
10194 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10195 #ifndef NDEBUG
10196 {"Slave_rows_last_search_algorithm_used",
10197 (char *)&show_replica_rows_last_search_algorithm_used, SHOW_FUNC,
10198 SHOW_SCOPE_GLOBAL},
10199 #endif
10200 {"Slow_launch_threads",
10201 (char *)&Per_thread_connection_handler::slow_launch_threads, SHOW_LONG,
10202 SHOW_SCOPE_ALL},
10203 {"Slow_queries", (char *)offsetof(System_status_var, long_query_count),
10204 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10205 {"Sort_merge_passes",
10206 (char *)offsetof(System_status_var, filesort_merge_passes),
10207 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10208 {"Sort_range", (char *)offsetof(System_status_var, filesort_range_count),
10209 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10210 {"Sort_rows", (char *)offsetof(System_status_var, filesort_rows),
10211 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10212 {"Sort_scan", (char *)offsetof(System_status_var, filesort_scan_count),
10213 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10214 {"Ssl_accept_renegotiates",
10215 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept_renegotiate,
10216 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10217 {"Ssl_accepts", (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept,
10218 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10219 {"Ssl_callback_cache_hits",
10220 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_cb_hits, SHOW_FUNC,
10221 SHOW_SCOPE_GLOBAL},
10222 {"Ssl_cipher", (char *)&show_ssl_get_cipher, SHOW_FUNC, SHOW_SCOPE_ALL},
10223 {"Ssl_cipher_list", (char *)&show_ssl_get_cipher_list, SHOW_FUNC,
10224 SHOW_SCOPE_ALL},
10225 {"Ssl_client_connects",
10226 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect, SHOW_FUNC,
10227 SHOW_SCOPE_GLOBAL},
10228 {"Ssl_connect_renegotiates",
10229 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect_renegotiate,
10230 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10231 {"Ssl_ctx_verify_depth",
10232 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_verify_depth, SHOW_FUNC,
10233 SHOW_SCOPE_GLOBAL},
10234 {"Ssl_ctx_verify_mode",
10235 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_verify_mode, SHOW_FUNC,
10236 SHOW_SCOPE_GLOBAL},
10237 {"Ssl_default_timeout", (char *)&show_ssl_get_default_timeout, SHOW_FUNC,
10238 SHOW_SCOPE_ALL},
10239 {"Ssl_finished_accepts",
10240 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept_good, SHOW_FUNC,
10241 SHOW_SCOPE_GLOBAL},
10242 {"Ssl_finished_connects",
10243 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect_good, SHOW_FUNC,
10244 SHOW_SCOPE_GLOBAL},
10245 {"Ssl_session_cache_hits",
10246 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_hits, SHOW_FUNC,
10247 SHOW_SCOPE_GLOBAL},
10248 {"Ssl_session_cache_misses",
10249 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_misses, SHOW_FUNC,
10250 SHOW_SCOPE_GLOBAL},
10251 {"Ssl_session_cache_mode",
10252 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_session_cache_mode,
10253 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10254 {"Ssl_session_cache_overflows",
10255 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_cache_full, SHOW_FUNC,
10256 SHOW_SCOPE_GLOBAL},
10257 {"Ssl_session_cache_size",
10258 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_get_cache_size,
10259 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10260 {"Ssl_session_cache_timeouts",
10261 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_timeouts, SHOW_FUNC,
10262 SHOW_SCOPE_GLOBAL},
10263 {"Ssl_sessions_reused", (char *)&show_ssl_session_reused, SHOW_FUNC,
10264 SHOW_SCOPE_ALL},
10265 {"Ssl_used_session_cache_entries",
10266 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_number, SHOW_FUNC,
10267 SHOW_SCOPE_GLOBAL},
10268 {"Ssl_verify_depth", (char *)&show_ssl_get_verify_depth, SHOW_FUNC,
10269 SHOW_SCOPE_ALL},
10270 {"Ssl_verify_mode", (char *)&show_ssl_get_verify_mode, SHOW_FUNC,
10271 SHOW_SCOPE_ALL},
10272 {"Ssl_version", (char *)&show_ssl_get_version, SHOW_FUNC, SHOW_SCOPE_ALL},
10273 {"Ssl_server_not_before",
10274 (char *)&Ssl_mysql_main_status::show_ssl_get_server_not_before, SHOW_FUNC,
10275 SHOW_SCOPE_ALL},
10276 {"Ssl_server_not_after",
10277 (char *)&Ssl_mysql_main_status::show_ssl_get_server_not_after, SHOW_FUNC,
10278 SHOW_SCOPE_ALL},
10279 {"Current_tls_ca", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_ca,
10280 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10281 {"Current_tls_capath",
10282 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_capath, SHOW_FUNC,
10283 SHOW_SCOPE_GLOBAL},
10284 {"Current_tls_cert", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_cert,
10285 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10286 {"Current_tls_key", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_key,
10287 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10288 {"Current_tls_version",
10289 (char *)&Ssl_mysql_main_status::show_ssl_get_tls_version, SHOW_FUNC,
10290 SHOW_SCOPE_GLOBAL},
10291 {"Current_tls_cipher",
10292 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_cipher, SHOW_FUNC,
10293 SHOW_SCOPE_GLOBAL},
10294 {"Current_tls_ciphersuites",
10295 (char *)&Ssl_mysql_main_status::show_ssl_get_tls_ciphersuites, SHOW_FUNC,
10296 SHOW_SCOPE_GLOBAL},
10297 {"Current_tls_crl", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_crl,
10298 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10299 {"Current_tls_crlpath",
10300 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_crlpath, SHOW_FUNC,
10301 SHOW_SCOPE_GLOBAL},
10302 {"Rsa_public_key", (char *)&show_rsa_public_key, SHOW_FUNC,
10303 SHOW_SCOPE_GLOBAL},
10304 {"Table_locks_immediate", (char *)&locks_immediate, SHOW_LONG,
10305 SHOW_SCOPE_GLOBAL},
10306 {"Table_locks_waited", (char *)&locks_waited, SHOW_LONG, SHOW_SCOPE_GLOBAL},
10307 {"Table_open_cache_hits",
10308 (char *)offsetof(System_status_var, table_open_cache_hits),
10309 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10310 {"Table_open_cache_misses",
10311 (char *)offsetof(System_status_var, table_open_cache_misses),
10312 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10313 {"Table_open_cache_overflows",
10314 (char *)offsetof(System_status_var, table_open_cache_overflows),
10315 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
10316 {"Tc_log_max_pages_used", (char *)&tc_log_max_pages_used, SHOW_LONG,
10317 SHOW_SCOPE_GLOBAL},
10318 {"Tc_log_page_size", (char *)&tc_log_page_size, SHOW_LONG_NOFLUSH,
10319 SHOW_SCOPE_GLOBAL},
10320 {"Tc_log_page_waits", (char *)&tc_log_page_waits, SHOW_LONG,
10321 SHOW_SCOPE_GLOBAL},
10322 #ifdef HAVE_POOL_OF_THREADS
10323 {"Threadpool_idle_threads", (char *)&show_threadpool_idle_threads,
10324 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10325 {"Threadpool_threads", (char *)&tp_stats.num_worker_threads, SHOW_INT,
10326 SHOW_SCOPE_GLOBAL},
10327 #endif
10328 {"Threads_cached",
10329 (char *)&Per_thread_connection_handler::blocked_pthread_count,
10330 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
10331 {"Threads_connected", (char *)&Connection_handler_manager::connection_count,
10332 SHOW_INT, SHOW_SCOPE_GLOBAL},
10333 {"Threads_created", (char *)&show_num_thread_created, SHOW_FUNC,
10334 SHOW_SCOPE_GLOBAL},
10335 {"Threads_running", (char *)&show_num_thread_running, SHOW_FUNC,
10336 SHOW_SCOPE_GLOBAL},
10337 {"Uptime", (char *)&show_starttime, SHOW_FUNC, SHOW_SCOPE_GLOBAL},
10338 #ifdef ENABLED_PROFILING
10339 {"Uptime_since_flush_status", (char *)&show_flushstatustime, SHOW_FUNC,
10340 SHOW_SCOPE_GLOBAL},
10341 #endif
10342 {"Ssl_session_cache_timeout",
10343 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_timeout, SHOW_FUNC,
10344 SHOW_SCOPE_GLOBAL},
10345 {"Tls_library_version", (char *)&show_tls_library_version, SHOW_FUNC,
10346 SHOW_SCOPE_GLOBAL},
10347 {NullS, NullS, SHOW_LONG, SHOW_SCOPE_ALL}};
10348
10349 36374 void add_terminator(vector<my_option> *options) {
10350 36374 my_option empty_element = {nullptr, 0, nullptr, nullptr, nullptr,
10351 nullptr, GET_NO_ARG, NO_ARG, 0, 0,
10352 0, nullptr, 0, nullptr};
10353
1/2
✓ Branch 0 taken 36374 times.
✗ Branch 1 not taken.
36374 options->push_back(empty_element);
10354 36374 }
10355
10356 14 static void print_server_version(void) {
10357 14 set_server_version();
10358
10359 14 print_explicit_version(server_version);
10360 14 }
10361
10362 /** Compares two options' names, treats - and _ the same */
10363 123458 static bool operator<(const my_option &a, const my_option &b) {
10364 123458 const char *sa = a.name;
10365 123458 const char *sb = b.name;
10366
3/4
✓ Branch 0 taken 653154 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 792 times.
✗ Branch 3 not taken.
653946 for (; *sa || *sb; sa++, sb++) {
10367
2/2
✓ Branch 0 taken 79370 times.
✓ Branch 1 taken 574576 times.
653946 if (*sa < *sb) {
10368
4/4
✓ Branch 0 taken 1514 times.
✓ Branch 1 taken 77856 times.
✓ Branch 2 taken 1220 times.
✓ Branch 3 taken 294 times.
79370 if (*sa == '-' && *sb == '_')
10369 1220 continue;
10370 else
10371 78150 return true;
10372 }
10373
2/2
✓ Branch 0 taken 46282 times.
✓ Branch 1 taken 528294 times.
574576 if (*sa > *sb) {
10374
4/4
✓ Branch 0 taken 1318 times.
✓ Branch 1 taken 44964 times.
✓ Branch 2 taken 974 times.
✓ Branch 3 taken 344 times.
46282 if (*sa == '_' && *sb == '-')
10375 974 continue;
10376 else
10377 45308 return false;
10378 }
10379 }
10380 assert(a.name == b.name);
10381 return false;
10382 }
10383
10384 14 static void print_help() {
10385 14 MEM_ROOT mem_root(key_memory_help, 4096);
10386
10387 14 all_options.pop_back();
10388
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 sys_var_add_options(&all_options, sys_var::PARSE_EARLY);
10389
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 14 times.
308 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++) {
10390
1/2
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
294 all_options.push_back(*opt);
10391 }
10392
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 add_plugin_options(&all_options, &mem_root);
10393
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 std::sort(all_options.begin(), all_options.end(), std::less<my_option>());
10394
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 add_terminator(&all_options);
10395
10396
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_print_help(&all_options[0]);
10397
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_print_variables(&all_options[0]);
10398
10399
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 mem_root.Clear();
10400 14 vector<my_option>().swap(all_options); // Deletes the vector contents.
10401 14 }
10402
10403 14 static void usage(void) {
10404
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 DBUG_TRACE;
10405
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if (!(default_charset_info = get_charset_by_csname(
10406 default_character_set_name, MY_CS_PRIMARY, MYF(MY_WME))))
10407 exit(MYSQLD_ABORT_EXIT);
10408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!default_collation_name)
10409 default_collation_name = default_charset_info->m_coll_name;
10410
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
14 if (is_help_or_validate_option() || opt_verbose) {
10411
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_progname = my_progname + dirname_length(my_progname);
10412 }
10413
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_server_version();
10414
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
10415
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts("Starts the MySQL database server.\n");
10416
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 printf("Usage: %s [OPTIONS]\n", my_progname);
10417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!opt_verbose)
10418 puts(
10419 "\nFor more help options (several pages), use mysqld --verbose "
10420 "--help.");
10421 else {
10422 #ifdef _WIN32
10423 puts(
10424 "NT and Win32 specific options:\n\
10425 --install Install the default service (NT).\n\
10426 --install-manual Install the default service started manually (NT).\n\
10427 --install service_name Install an optional service (NT).\n\
10428 --install-manual service_name Install an optional service started manually (NT).\n\
10429 --remove Remove the default service from the service list (NT).\n\
10430 --remove service_name Remove the service_name from the service list (NT).\n\
10431 --enable-named-pipe Only to be used for the default server (NT).\n\
10432 --standalone Dummy option to start as a standalone server (NT).\
10433 ");
10434 puts("");
10435 #endif
10436
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_defaults(MYSQL_CONFIG_NAME, load_default_groups);
10437
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts("");
10438
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 set_ports();
10439
10440 /* Print out all the options including plugin supplied options */
10441
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_help();
10442
10443
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (!dynamic_plugins_are_initialized) {
10444
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 puts(
10445 "\n\
10446 Plugins have parameters that are not reflected in this list\n\
10447 because execution stopped before plugins were initialized.");
10448 }
10449
10450
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts(
10451 "\n\
10452 To see what values a running MySQL server is using, type\n\
10453 'mysqladmin variables' instead of 'mysqld --verbose --help'.");
10454 }
10455 14 }
10456
10457 /**
10458 Initialize MySQL global variables to default values.
10459
10460 @note
10461 The reason to set a lot of global variables to zero is that
10462 on some exotic platforms global variables are
10463 not set to 0 when a program starts.
10464
10465 We don't need to set variables referred to in my_long_options
10466 as these are initialized by my_getopt.
10467 */
10468
10469 12142 static int mysql_init_variables() {
10470 /* Things reset to zero */
10471 12142 opt_skip_replica_start = false;
10472 12142 pidfile_name[0] = 0;
10473 12142 myisam_test_invalid_symlink = test_if_data_home_dir;
10474 12142 opt_general_log = opt_slow_log = false;
10475 12142 opt_disable_networking = opt_skip_show_db = false;
10476 12142 opt_skip_name_resolve = false;
10477 12142 opt_general_logname = opt_binlog_index_name = opt_slow_logname = nullptr;
10478 12142 opt_tc_log_file = "tc.log"; // no hostname in tc_log file name !
10479 12142 opt_myisam_log = false;
10480 12142 mqh_used = false;
10481 12142 cleanup_done = 0;
10482 12142 server_id_supplied = false;
10483 12142 select_errors = ha_open_options = 0;
10484 12142 atomic_replica_open_temp_tables = 0;
10485 12142 opt_endinfo = using_udf_functions = false;
10486 12142 opt_using_transactions = false;
10487 12142 set_connection_events_loop_aborted(false);
10488 12142 set_mysqld_offline_mode(false);
10489 12142 set_mysqld_partial_revokes(opt_partial_revokes);
10490 12142 server_operational_state = SERVER_BOOTING;
10491 12142 aborted_threads = 0;
10492 12142 delayed_insert_threads = delayed_insert_writes = delayed_rows_in_use = 0;
10493 12142 delayed_insert_errors = 0;
10494 12142 specialflag = 0;
10495 12142 binlog_cache_use = binlog_cache_disk_use = 0;
10496 12142 mysqld_user = mysqld_chroot = opt_init_file = opt_bin_logname = nullptr;
10497 12142 prepared_stmt_count = 0;
10498 12142 mysqld_unix_port = opt_mysql_tmpdir = my_bind_addr_str = NullS;
10499 12142 new (&mysql_tmpdir_list) MY_TMPDIR;
10500 12142 memset(&global_status_var, 0, sizeof(global_status_var));
10501 12142 opt_large_pages = false;
10502 12142 opt_super_large_pages = false;
10503 #if defined(ENABLED_DEBUG_SYNC)
10504 12142 opt_debug_sync_timeout = 0;
10505 #endif /* defined(ENABLED_DEBUG_SYNC) */
10506 12142 server_uuid[0] = 0;
10507
10508 /* Character sets */
10509 12142 system_charset_info = &my_charset_utf8_general_ci;
10510 12142 files_charset_info = &my_charset_utf8_general_ci;
10511 12142 national_charset_info = &my_charset_utf8_general_ci;
10512 12142 table_alias_charset = &my_charset_bin;
10513 12142 character_set_filesystem = &my_charset_bin;
10514
10515 12142 opt_specialflag = 0;
10516 12142 pidfile_name_ptr = pidfile_name;
10517 12142 lc_messages_dir_ptr = lc_messages_dir;
10518 12142 protocol_version = PROTOCOL_VERSION;
10519 12142 what_to_log = ~(1L << (uint)COM_TIME);
10520 12142 refresh_version = 1L; /* Increments on each reload */
10521 12142 my_stpcpy(server_version, MYSQL_SERVER_VERSION);
10522 12142 key_caches.clear();
10523
2/4
✓ Branch 0 taken 12142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12142 times.
12142 if (!(dflt_key_cache = get_or_create_key_cache(std::string_view{
10524 12142 default_key_cache_base.str, default_key_cache_base.length}))) {
10525 LogErr(ERROR_LEVEL, ER_KEYCACHE_OOM);
10526 return 1;
10527 }
10528 /* set key_cache_hash.default_value = dflt_key_cache */
10529 12142 multi_keycache_init();
10530
10531 /* Replication parameters */
10532 12142 master_info_file = "master.info";
10533 12142 relay_log_info_file = "relay-log.info";
10534 12142 report_user = report_password = report_host = nullptr; /* TO BE DELETED */
10535 12142 opt_relay_logname = opt_relaylog_index_name = nullptr;
10536 12142 opt_relaylog_index_name_supplied = false;
10537 12142 opt_relay_logname_supplied = false;
10538 12142 log_bin_basename = nullptr;
10539 12142 log_bin_index = nullptr;
10540
10541 /* Handler variables */
10542 12142 total_ha_2pc = 0;
10543 /* Variables in libraries */
10544 12142 charsets_dir = nullptr;
10545 12142 default_character_set_name = MYSQL_DEFAULT_CHARSET_NAME;
10546 12142 default_collation_name = compiled_default_collation_name;
10547 12142 character_set_filesystem_name = "binary";
10548 12142 lc_messages = mysqld_default_locale_name;
10549 12142 lc_time_names_name = mysqld_default_locale_name;
10550 12142 opt_replication_optimize_for_static_plugin_config = false;
10551 12142 opt_replication_sender_observe_commit_only = false;
10552
10553 /* Variables that depends on compile options */
10554 #ifndef NDEBUG
10555 12142 default_dbug_option =
10556 IF_WIN("d:t:i:O,\\mysqld.trace", "d:t:i:o,/tmp/mysqld.trace");
10557 #endif
10558 #ifdef ENABLED_PROFILING
10559 12142 have_profiling = SHOW_OPTION_YES;
10560 #else
10561 have_profiling = SHOW_OPTION_NO;
10562 #endif
10563
10564 12142 have_symlink = SHOW_OPTION_YES;
10565
10566 12142 have_dlopen = SHOW_OPTION_YES;
10567
10568 12142 have_query_cache = SHOW_OPTION_NO;
10569
10570 12142 have_geometry = SHOW_OPTION_YES;
10571
10572 12142 have_rtree_keys = SHOW_OPTION_YES;
10573
10574 /* Always true */
10575 12142 have_compress = SHOW_OPTION_YES;
10576 #if defined(_WIN32)
10577 shared_memory_base_name = default_shared_memory_base_name;
10578 #endif
10579
10580 12142 have_backup_locks = SHOW_OPTION_YES;
10581 12142 have_backup_safe_binlog_info = SHOW_OPTION_YES;
10582 12142 have_snapshot_cloning = SHOW_OPTION_YES;
10583
10584 12142 return 0;
10585 }
10586
10587 /**
10588 Check if it is a global replication filter setting.
10589
10590 @param argument The setting of startup option --replicate-*.
10591
10592 @retval
10593 0 OK
10594 @retval
10595 1 Error
10596 */
10597 363 static bool is_rpl_global_filter_setting(char *argument) {
10598
1/2
✓ Branch 0 taken 363 times.
✗ Branch 1 not taken.
363 DBUG_TRACE;
10599
10600 363 bool res = false;
10601 363 char *p = strchr(argument, ':');
10602
2/2
✓ Branch 0 taken 267 times.
✓ Branch 1 taken 96 times.
363 if (p == nullptr) res = true;
10603
10604 363 return res;
10605 363 }
10606
10607 /**
10608 Extract channel name and filter value from argument.
10609
10610 @param [out] channel_name The name of the channel.
10611 @param [out] filter_val The value of filter.
10612 @param argument The setting of startup option --replicate-*.
10613 */
10614 96 void parse_filter_arg(char **channel_name, char **filter_val, char *argument) {
10615
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 DBUG_TRACE;
10616
10617 96 char *p = strchr(argument, ':');
10618
10619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 assert(p != nullptr);
10620
10621 /*
10622 If argument='channel_1:db1', then channel_name='channel_1'
10623 and filter_val='db1'; If argument=':db1', then channel_name=''
10624 and filter_val='db1'.
10625 */
10626 96 *channel_name = argument;
10627 96 *filter_val = p + 1;
10628 96 *p = 0;
10629 96 }
10630
10631 /**
10632 Extract channel name and filter value from argument.
10633
10634 @param [out] key The db is rewritten from.
10635 @param [out] val The db is rewritten to.
10636 @param argument The value of filter.
10637
10638 @retval
10639 0 OK
10640 @retval
10641 1 Error
10642 */
10643 54 static int parse_replicate_rewrite_db(char **key, char **val, char *argument) {
10644
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 DBUG_TRACE;
10645 char *p;
10646 54 *key = argument;
10647
10648
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 46 times.
54 if (!(p = strstr(argument, "->"))) {
10649
8/16
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
8 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_MISSING_ARROW);
10650 8 return 1;
10651 }
10652 46 *val = p + 2;
10653
10654
3/4
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
46 while (p > argument && my_isspace(mysqld_charset, p[-1])) p--;
10655 46 *p = 0;
10656
10657
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 44 times.
46 if (!**key) {
10658
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_EMPTY_FROM);
10659 2 return 1;
10660 }
10661
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 39 times.
47 while (**val && my_isspace(mysqld_charset, **val)) (*val)++;
10662
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 39 times.
44 if (!**val) {
10663
8/16
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
5 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_EMPTY_TO);
10664 5 return 1;
10665 }
10666
10667 39 return 0;
10668 54 }
10669
10670 704239 bool mysqld_get_one_option(int optid,
10671 const struct my_option *opt [[maybe_unused]],
10672 char *argument) {
10673 704239 Rpl_filter *rpl_filter = nullptr;
10674 char *filter_val;
10675 char *channel_name;
10676
10677
1/2
✓ Branch 0 taken 704239 times.
✗ Branch 1 not taken.
704239 auto *sysvar = intern_find_sys_var(opt->name, strlen(opt->name));
10678
4/4
✓ Branch 0 taken 472685 times.
✓ Branch 1 taken 231554 times.
✓ Branch 2 taken 7864 times.
✓ Branch 3 taken 464821 times.
704239 if (sysvar && sysvar->m_persisted_alias &&
10679
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 7701 times.
7864 sysvar->m_is_persisted_deprecated) {
10680 /*
10681 At this point, my_handle_options (through setval and
10682 setval_source) has set the source for itself. It was set using
10683 direct access to the my_option object, so it is really the
10684 source object that is a member of this sysvar that has been set.
10685 In case this is a deprecated alias, that does not help, because
10686 the high-level getters and setters will get and set the value in
10687 the base variable, not the alias. Therefore, we copy the source
10688 from the alias to the base variable, using a low-level getter in
10689 the alias and a high-level setter in the alias.
10690 */
10691 163 auto *source = sysvar->get_option()->arg_source;
10692
1/2
✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
163 sysvar->set_source(source->m_source);
10693
1/2
✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
163 sysvar->set_source_name(source->m_path_name);
10694
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 39 times.
163 if (source->m_source != PERSISTED) {
10695 /*
10696 Generate the deprecation warning. But not if we are loading
10697 it from the persisted variables file (i.e., this is a variable
10698 having the PERSIST_AS_READONLY flag set): in that case a more
10699 specific warning was already generated when loading the
10700 persisted variable.
10701 */
10702 124 const char *ds = sysvar->get_deprecation_substitute();
10703
2/4
✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124 times.
✗ Branch 3 not taken.
124 if (ds) push_deprecated_warn(nullptr, opt->name, ds);
10704 }
10705 }
10706
10707
62/74
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 248 times.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 12713 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 233 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 3280 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 14 taken 35019 times.
✓ Branch 15 taken 29 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 146 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4772 times.
✓ Branch 24 taken 12 times.
✓ Branch 25 taken 34 times.
✓ Branch 26 taken 63 times.
✓ Branch 27 taken 54 times.
✓ Branch 28 taken 18 times.
✓ Branch 29 taken 8 times.
✓ Branch 30 taken 59 times.
✓ Branch 31 taken 27 times.
✓ Branch 32 taken 40 times.
✓ Branch 33 taken 86 times.
✓ Branch 34 taken 3254 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 41 times.
✓ Branch 38 taken 11596 times.
✓ Branch 39 taken 5 times.
✓ Branch 40 taken 18 times.
✓ Branch 41 taken 11752 times.
✓ Branch 42 taken 337 times.
✓ Branch 43 taken 11436 times.
✓ Branch 44 taken 865 times.
✓ Branch 45 taken 1501 times.
✓ Branch 46 taken 2271 times.
✓ Branch 47 taken 926 times.
✓ Branch 48 taken 11675 times.
✓ Branch 49 taken 2 times.
✓ Branch 50 taken 2 times.
✓ Branch 51 taken 2 times.
✓ Branch 52 taken 7 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 370 times.
✓ Branch 58 taken 137 times.
✓ Branch 59 taken 2782 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 4 times.
✓ Branch 62 taken 5 times.
✓ Branch 63 taken 2 times.
✓ Branch 64 taken 1 times.
✓ Branch 65 taken 57 times.
✓ Branch 66 taken 260 times.
✓ Branch 67 taken 100 times.
✓ Branch 68 taken 1 times.
✓ Branch 69 taken 1 times.
✓ Branch 70 taken 103 times.
✓ Branch 71 taken 188 times.
✓ Branch 72 taken 1 times.
✓ Branch 73 taken 587339 times.
704239 switch (optid) {
10708 268 case '#':
10709 #ifndef NDEBUG
10710
2/4
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 268 times.
✗ Branch 3 not taken.
268 DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
10711 #endif
10712 268 opt_endinfo = true; /* unireg: memory allocation */
10713 268 break;
10714 2 case 'a':
10715 2 global_system_variables.sql_mode = MODE_ANSI;
10716 2 global_system_variables.transaction_isolation = ISO_SERIALIZABLE;
10717 2 break;
10718 248 case 'b':
10719
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 strmake(mysql_home, argument, sizeof(mysql_home) - 1);
10720 248 mysql_home_ptr = mysql_home;
10721 248 break;
10722 31 case 'C':
10723
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 1 times.
31 if (default_collation_name == compiled_default_collation_name)
10724 30 default_collation_name = nullptr;
10725 31 break;
10726 12713 case 'h':
10727
1/2
✓ Branch 0 taken 12713 times.
✗ Branch 1 not taken.
12713 strmake(mysql_real_data_home, argument, sizeof(mysql_real_data_home) - 1);
10728 /* Correct pointer set by my_getopt */
10729 12713 mysql_real_data_home_ptr = mysql_real_data_home;
10730 12713 break;
10731 case 'u':
10732 if (!mysqld_user || !strcmp(mysqld_user, argument))
10733 mysqld_user = argument;
10734 else
10735 LogErr(WARNING_LEVEL, ER_THE_USER_ABIDES, argument, mysqld_user);
10736 break;
10737 3 case 's':
10738
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (argument && argument[0] == '0') {
10739
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_DEPRECATE_MSG_NO_REPLACEMENT,
10740 "Disabling symbolic links using --skip-symbolic-links"
10741 " (or equivalent) is the default. Consider not using"
10742 " this option as it");
10743 } else {
10744
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(WARNING_LEVEL, ER_DEPRECATE_MSG_NO_REPLACEMENT,
10745 "Enabling symbolic using --symbolic-links/-s (or equivalent)");
10746 }
10747 3 break;
10748 case 'L':
10749 push_deprecated_warn(nullptr, "--language/-l", "'--lc-messages-dir'");
10750 [[fallthrough]];
10751 233 case OPT_LC_MESSAGES_DIRECTORY:
10752
1/2
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
233 strmake(lc_messages_dir, argument, sizeof(lc_messages_dir) - 1);
10753 233 lc_messages_dir_ptr = lc_messages_dir;
10754 233 break;
10755 1 case OPT_SHOW_SLAVE_AUTH_INFO_DEPRECATED:
10756
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn(nullptr, "show-slave-auth-info",
10757 "show-replica-auth-info");
10758 1 break;
10759 3280 case OPT_BINLOG_FORMAT:
10760 3280 binlog_format_used = true;
10761 3280 break;
10762 2 case OPT_BINLOG_MAX_FLUSH_QUEUE_TIME:
10763
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 push_deprecated_warn_no_replacement(nullptr,
10764 "--binlog_max_flush_queue_time");
10765 2 break;
10766 22 case OPT_EXPIRE_LOGS_DAYS:
10767
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 push_deprecated_warn(nullptr, "expire-logs-days",
10768 "binlog_expire_logs_seconds");
10769 22 expire_logs_days_supplied = true;
10770 22 break;
10771 22 case OPT_BINLOG_EXPIRE_LOGS_SECONDS:
10772 22 binlog_expire_logs_seconds_supplied = true;
10773 22 break;
10774 35019 case OPT_SSL_KEY:
10775 case OPT_SSL_CERT:
10776 case OPT_SSL_CA:
10777 case OPT_SSL_CAPATH:
10778 case OPT_SSL_CIPHER:
10779 case OPT_TLS_CIPHERSUITES:
10780 case OPT_SSL_CRL:
10781 case OPT_SSL_CRLPATH:
10782 /*
10783 Enable use of SSL if we are using any ssl option.
10784 One can disable SSL later by using --skip-ssl or --ssl=0.
10785 */
10786 35019 opt_use_ssl = true;
10787 35019 break;
10788 29 case OPT_TLS_VERSION:
10789 29 opt_use_ssl = true;
10790
2/4
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
29 if (validate_tls_version(argument)) {
10791 LogErr(ERROR_LEVEL, ER_INVALID_TLS_VERSION, argument);
10792 return true;
10793 }
10794 29 break;
10795 4 case OPT_USE_ADMIN_SSL:
10796
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (opt_use_admin_ssl)
10797
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--admin-ssl=on");
10798 else
10799
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 push_deprecated_warn(nullptr, "--admin-ssl=off",
10800 "--admin-tls-version=invalid");
10801 4 break;
10802 146 case OPT_USE_SSL:
10803
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 140 times.
146 if (opt_use_ssl)
10804
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 push_deprecated_warn_no_replacement(nullptr, "--ssl=on");
10805 else
10806
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 push_deprecated_warn(nullptr, "--ssl=off", "--tls-version=invalid");
10807 146 break;
10808 case OPT_ADMIN_SSL_KEY:
10809 case OPT_ADMIN_SSL_CERT:
10810 case OPT_ADMIN_SSL_CA:
10811 case OPT_ADMIN_SSL_CAPATH:
10812 case OPT_ADMIN_SSL_CIPHER:
10813 case OPT_ADMIN_TLS_CIPHERSUITES:
10814 case OPT_ADMIN_SSL_CRL:
10815 case OPT_ADMIN_SSL_CRLPATH:
10816 /*
10817 Enable use of SSL if we are using any ssl option.
10818 One can disable SSL later by using --skip-admin-ssl or --admin-ssl=0.
10819 */
10820 g_admin_ssl_configured = true;
10821 opt_use_admin_ssl = true;
10822 break;
10823 case OPT_ADMIN_TLS_VERSION:
10824 g_admin_ssl_configured = true;
10825 opt_use_admin_ssl = true;
10826 if (validate_tls_version(argument)) {
10827 LogErr(ERROR_LEVEL, ER_INVALID_TLS_VERSION, argument);
10828 return true;
10829 }
10830 break;
10831 case 'V':
10832 print_server_version();
10833 exit(MYSQLD_SUCCESS_EXIT);
10834 1 case 'T':
10835
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 test_flags = argument ? (uint)atoi(argument) : 0;
10836 1 opt_endinfo = true;
10837 1 break;
10838 case (int)OPT_ISAM_LOG:
10839 opt_myisam_log = true;
10840 break;
10841 4772 case (int)OPT_BIN_LOG:
10842 4772 opt_bin_log = (argument != disabled_my_option);
10843
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 4439 times.
4772 if (!opt_bin_log) {
10844 // Clear the binlog basename used by any previous --log-bin
10845
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 if (opt_bin_logname) {
10846
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 my_free(opt_bin_logname);
10847 333 opt_bin_logname = nullptr;
10848 }
10849 }
10850 4772 log_bin_supplied = true;
10851 4772 break;
10852 12 case (int)OPT_REPLICA_ENABLE_EVENT: {
10853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::ostringstream message{};
10854
4/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
12 if (Rpl_event_ctx::get_instance().process_argument(argument, message)) {
10855
9/18
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
6 LogErr(ERROR_LEVEL, ER_RPL_ENABLE_EVENT_ADD_WILD_PATTERN_FAILED,
10856 argument, message.str().c_str());
10857 6 return true;
10858 }
10859 6 break;
10860
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 }
10861 34 case (int)OPT_REPLICATE_IGNORE_DB: {
10862
3/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 12 times.
34 if (is_rpl_global_filter_setting(argument)) {
10863
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 rpl_global_filter.add_ignore_db(argument);
10864
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 rpl_global_filter.ignore_db_statistics.set_all(
10865 CONFIGURED_BY_STARTUP_OPTIONS);
10866 } else {
10867
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
10868
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10869
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter->add_ignore_db(filter_val);
10870
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter->ignore_db_statistics.set_all(
10871 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10872 }
10873 34 break;
10874 }
10875 63 case (int)OPT_REPLICATE_DO_DB: {
10876
3/4
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 20 times.
63 if (is_rpl_global_filter_setting(argument)) {
10877
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 rpl_global_filter.add_do_db(argument);
10878
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 rpl_global_filter.do_db_statistics.set_all(
10879 CONFIGURED_BY_STARTUP_OPTIONS);
10880 } else {
10881
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 parse_filter_arg(&channel_name, &filter_val, argument);
10882
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10883
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter->add_do_db(filter_val);
10884
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter->do_db_statistics.set_all(
10885 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10886 }
10887 63 break;
10888 }
10889 54 case (int)OPT_REPLICATE_REWRITE_DB: {
10890 char *key, *val;
10891
3/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 14 times.
54 if (is_rpl_global_filter_setting(argument)) {
10892
3/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 28 times.
43 if (parse_replicate_rewrite_db(&key, &val, argument)) return true;
10893
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 rpl_global_filter.add_db_rewrite(key, val);
10894
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 rpl_global_filter.rewrite_db_statistics.set_all(
10895 CONFIGURED_BY_STARTUP_OPTIONS);
10896 } else {
10897
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 parse_filter_arg(&channel_name, &filter_val, argument);
10898
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10899
3/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 11 times.
14 if (parse_replicate_rewrite_db(&key, &val, filter_val)) return true;
10900
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->add_db_rewrite(key, val);
10901
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->rewrite_db_statistics.set_all(
10902 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10903 }
10904 39 break;
10905 }
10906
10907 18 case (int)OPT_BINLOG_IGNORE_DB: {
10908
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 binlog_filter->add_ignore_db(argument);
10909 18 break;
10910 }
10911 8 case (int)OPT_BINLOG_DO_DB: {
10912
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 binlog_filter->add_do_db(argument);
10913 8 break;
10914 }
10915 59 case (int)OPT_REPLICATE_DO_TABLE: {
10916
3/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 12 times.
59 if (is_rpl_global_filter_setting(argument)) {
10917
3/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 46 times.
47 if (rpl_global_filter.add_do_table_array(argument)) {
10918
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_DO_TABLE, argument);
10919 1 return true;
10920 }
10921
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 rpl_global_filter.do_table_statistics.set_all(
10922 CONFIGURED_BY_STARTUP_OPTIONS);
10923 } else {
10924
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
10925
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10926
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_do_table_array(filter_val)) {
10927
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_DO_TABLE, argument);
10928 1 return true;
10929 }
10930
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->do_table_statistics.set_all(
10931 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10932 }
10933 57 break;
10934 }
10935 27 case (int)OPT_REPLICATE_WILD_DO_TABLE: {
10936
3/4
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 12 times.
27 if (is_rpl_global_filter_setting(argument)) {
10937
3/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 14 times.
15 if (rpl_global_filter.add_wild_do_table(argument)) {
10938
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_DO_TABLE_FAILED, argument);
10939 1 return true;
10940 }
10941
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 rpl_global_filter.wild_do_table_statistics.set_all(
10942 CONFIGURED_BY_STARTUP_OPTIONS);
10943 } else {
10944
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
10945
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10946
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_wild_do_table(filter_val)) {
10947
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_DO_TABLE_FAILED, argument);
10948 1 return true;
10949 }
10950
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->wild_do_table_statistics.set_all(
10951 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10952 }
10953 25 break;
10954 }
10955 40 case (int)OPT_REPLICATE_WILD_IGNORE_TABLE: {
10956
3/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 12 times.
40 if (is_rpl_global_filter_setting(argument)) {
10957
3/4
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 27 times.
28 if (rpl_global_filter.add_wild_ignore_table(argument)) {
10958
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_IGNORE_TABLE_FAILED,
10959 argument);
10960 1 return true;
10961 }
10962
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 rpl_global_filter.wild_ignore_table_statistics.set_all(
10963 CONFIGURED_BY_STARTUP_OPTIONS);
10964 } else {
10965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
10966
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10967
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_wild_ignore_table(filter_val)) {
10968
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_IGNORE_TABLE_FAILED,
10969 argument);
10970 1 return true;
10971 }
10972
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->wild_ignore_table_statistics.set_all(
10973 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10974 }
10975 38 break;
10976 }
10977 86 case (int)OPT_REPLICATE_IGNORE_TABLE: {
10978
3/4
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 14 times.
86 if (is_rpl_global_filter_setting(argument)) {
10979
3/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 71 times.
72 if (rpl_global_filter.add_ignore_table_array(argument)) {
10980
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_IGNORE_TABLE, argument);
10981 1 return true;
10982 }
10983
1/2
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
71 rpl_global_filter.ignore_table_statistics.set_all(
10984 CONFIGURED_BY_STARTUP_OPTIONS);
10985 } else {
10986
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 parse_filter_arg(&channel_name, &filter_val, argument);
10987
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
10988
3/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 13 times.
14 if (rpl_filter->add_ignore_table_array(filter_val)) {
10989
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_IGNORE_TABLE, argument);
10990 1 return true;
10991 }
10992
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 rpl_filter->ignore_table_statistics.set_all(
10993 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
10994 }
10995 84 break;
10996 }
10997 3254 case (int)OPT_MASTER_RETRY_COUNT:
10998
1/2
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
3254 push_deprecated_warn(nullptr, "--master-retry-count",
10999 "'CHANGE REPLICATION SOURCE TO "
11000 "SOURCE_RETRY_COUNT = <num>'");
11001 3254 break;
11002 case (int)OPT_SKIP_NEW:
11003 opt_specialflag |= SPECIAL_NO_NEW_FUNC;
11004 delay_key_write_options = DELAY_KEY_WRITE_NONE;
11005 myisam_concurrent_insert = 0;
11006 myisam_recover_options = HA_RECOVER_OFF;
11007 sp_automatic_privileges = false;
11008 my_enable_symlinks = false;
11009 ha_open_options &= ~(HA_OPEN_ABORT_IF_CRASHED | HA_OPEN_DELAY_KEY_WRITE);
11010 break;
11011 1 case (int)OPT_SKIP_HOST_CACHE_DEPRECATED:
11012 1 opt_specialflag |= SPECIAL_NO_HOST_CACHE;
11013
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn(nullptr, "--skip-host-cache",
11014 "SET GLOBAL host_cache_size=0");
11015 1 break;
11016 41 case (int)OPT_SKIP_RESOLVE:
11017
5/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 39 times.
44 if (argument && (argument == disabled_my_option ||
11018
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
3 !my_strcasecmp(system_charset_info, argument, "OFF")))
11019 2 opt_skip_name_resolve = false;
11020 else {
11021 39 opt_skip_name_resolve = true;
11022 39 opt_specialflag |= SPECIAL_NO_RESOLVE;
11023 }
11024 41 break;
11025 11596 case (int)OPT_WANT_CORE:
11026 11596 test_flags |= TEST_CORE_ON_SIGNAL;
11027 11596 opt_corefile = (argument != disabled_my_option);
11028 11596 break;
11029 5 case (int)OPT_COREDUMPER:
11030 5 test_flags |= TEST_CORE_ON_SIGNAL;
11031 5 opt_libcoredumper = (argument != disabled_my_option);
11032 5 break;
11033 18 case (int)OPT_SKIP_STACK_TRACE:
11034 18 test_flags |= TEST_NO_STACKTRACE;
11035 18 break;
11036 11752 case OPT_SERVER_ID:
11037 /*
11038 Consider that one received a Server Id when 2 conditions are present:
11039 1) The argument is on the list
11040 2) There is a value present
11041 */
11042 11752 server_id_supplied = (*argument != 0);
11043 11752 break;
11044 337 case OPT_LOWER_CASE_TABLE_NAMES:
11045 337 lower_case_table_names_used = true;
11046 337 break;
11047 #if defined(ENABLED_DEBUG_SYNC)
11048 11436 case OPT_DEBUG_SYNC_TIMEOUT:
11049 /*
11050 Debug Sync Facility. See debug_sync.cc.
11051 Default timeout for WAIT_FOR action.
11052 Default value is zero (facility disabled).
11053 If option is given without an argument, supply a non-zero value.
11054 */
11055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11436 times.
11436 if (!argument) {
11056 /* purecov: begin tested */
11057 opt_debug_sync_timeout = DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT;
11058 /* purecov: end */
11059 }
11060 11436 break;
11061 #endif /* defined(ENABLED_DEBUG_SYNC) */
11062 865 case OPT_LOG_ERROR:
11063 /*
11064 "No --log-error" == "write errors to stderr",
11065 "--log-error without argument" == "write errors to a file".
11066 */
11067
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 863 times.
865 if (argument == nullptr) /* no argument */
11068 2 log_error_dest = "";
11069 865 break;
11070
11071 1501 case OPT_EARLY_PLUGIN_LOAD:
11072
1/2
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
1501 free_list(opt_early_plugin_load_list_ptr);
11073
2/4
✓ Branch 0 taken 1501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1501 times.
✗ Branch 3 not taken.
1501 opt_early_plugin_load_list_ptr->push_back(new i_string(argument));
11074 1501 break;
11075 2271 case OPT_PLUGIN_LOAD:
11076
1/2
✓ Branch 0 taken 2271 times.
✗ Branch 1 not taken.
2271 free_list(opt_plugin_load_list_ptr);
11077 [[fallthrough]];
11078 3197 case OPT_PLUGIN_LOAD_ADD:
11079
2/4
✓ Branch 0 taken 3197 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3197 times.
✗ Branch 3 not taken.
3197 opt_plugin_load_list_ptr->push_back(new i_string(argument));
11080 3197 break;
11081 11675 case OPT_PFS_INSTRUMENT: {
11082 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
11083 /*
11084 Parse instrument name and value from argument string. Handle leading
11085 and trailing spaces. Also handle single quotes.
11086
11087 Acceptable:
11088 performance_schema_instrument = ' foo/%/bar/ = ON '
11089 performance_schema_instrument = '%=OFF'
11090 Not acceptable:
11091 performance_schema_instrument = '' foo/%/bar = ON ''
11092 performance_schema_instrument = '%='OFF''
11093 */
11094 11675 char *name = argument, *p = nullptr, *val = nullptr;
11095 11675 bool quote = false; /* true if quote detected */
11096 11675 bool error = true; /* false if no errors detected */
11097 11675 const int PFS_BUFFER_SIZE = 128;
11098 char orig_argument[PFS_BUFFER_SIZE + 1];
11099 11675 orig_argument[0] = 0;
11100
11101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11675 times.
11675 if (!argument) goto pfs_error;
11102
11103 /* Save original argument string for error reporting */
11104 11675 strncpy(orig_argument, argument, PFS_BUFFER_SIZE);
11105
11106 /* Split instrument name and value at the equal sign */
11107
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11671 times.
11675 if (!(p = strchr(argument, '='))) goto pfs_error;
11108
11109 /* Get option value */
11110 11671 val = p + 1;
11111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11671 times.
11671 if (!*val) goto pfs_error;
11112
11113 /* Trim leading spaces and quote from the instrument name */
11114
5/6
✓ Branch 0 taken 11683 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 11675 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 11671 times.
11683 while (*name && (my_isspace(mysqld_charset, *name) || (*name == '\''))) {
11115 /* One quote allowed */
11116
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (*name == '\'') {
11117
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!quote)
11118 4 quote = true;
11119 else
11120 goto pfs_error;
11121 }
11122 12 name++;
11123 }
11124
11125 /* Trim trailing spaces from instrument name */
11126
3/4
✓ Branch 0 taken 11692 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 11671 times.
11692 while ((p > name) && my_isspace(mysqld_charset, p[-1])) p--;
11127 11671 *p = 0;
11128
11129 /* Remove trailing slash from instrument name */
11130
3/4
✓ Branch 0 taken 11671 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11670 times.
11671 if (p > name && (p[-1] == '/')) p[-1] = 0;
11131
11132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11671 times.
11671 if (!*name) goto pfs_error;
11133
11134 /* Trim leading spaces from option value */
11135
3/4
✓ Branch 0 taken 11687 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 11671 times.
11687 while (*val && my_isspace(mysqld_charset, *val)) val++;
11136
11137 /* Trim trailing spaces and matching quote from value */
11138 11671 p = val + strlen(val);
11139
5/6
✓ Branch 0 taken 11680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 11675 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 11670 times.
11680 while (p > val && (my_isspace(mysqld_charset, p[-1]) || p[-1] == '\'')) {
11140 /* One matching quote allowed */
11141
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (p[-1] == '\'') {
11142
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 if (quote)
11143 4 quote = false;
11144 else
11145 1 goto pfs_error;
11146 }
11147 9 p--;
11148 }
11149
11150 11670 *p = 0;
11151
11152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11670 times.
11670 if (!*val) goto pfs_error;
11153
11154 /* Add instrument name and value to array of configuration options */
11155
3/4
✓ Branch 0 taken 11670 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11668 times.
11670 if (add_pfs_instr_to_array(name, val)) goto pfs_error;
11156
11157 11668 error = false;
11158
11159 11675 pfs_error:
11160
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 11668 times.
11675 if (error) {
11161
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_INVALID_INSTRUMENT, orig_argument);
11162 7 return false;
11163 }
11164 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
11165 11668 break;
11166 }
11167 2 case OPT_THREAD_CACHE_SIZE:
11168 2 thread_cache_size_specified = true;
11169 2 break;
11170 2 case OPT_HOST_CACHE_SIZE:
11171 2 host_cache_size_specified = true;
11172 2 break;
11173 2 case OPT_TABLE_DEFINITION_CACHE:
11174 2 table_definition_cache_specified = true;
11175 2 break;
11176 7 case OPT_SKIP_INNODB:
11177
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_INNODB_MANDATORY);
11178 7 break;
11179 case OPT_AVOID_TEMPORAL_UPGRADE:
11180 push_deprecated_warn_no_replacement(nullptr, "avoid_temporal_upgrade");
11181 break;
11182 case OPT_SHOW_OLD_TEMPORALS:
11183 push_deprecated_warn_no_replacement(nullptr, "show_old_temporals");
11184 break;
11185 case 'p':
11186 if (argument) {
11187 char *start = argument;
11188 my_free(opt_keyring_migration_password);
11189 opt_keyring_migration_password =
11190 my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
11191 while (*argument) *argument++ = 'x';
11192 if (*start) start[1] = 0;
11193 } else
11194 opt_keyring_migration_password = get_tty_password(NullS);
11195 migrate_connect_options = true;
11196 break;
11197 case OPT_KEYRING_MIGRATION_USER:
11198 case OPT_KEYRING_MIGRATION_HOST:
11199 case OPT_KEYRING_MIGRATION_SOCKET:
11200 case OPT_KEYRING_MIGRATION_PORT:
11201 migrate_connect_options = true;
11202 break;
11203 370 case OPT_LOG_REPLICA_UPDATES:
11204 370 log_replica_updates_supplied = true;
11205 370 break;
11206 137 case OPT_REPLICA_PRESERVE_COMMIT_ORDER:
11207 137 replica_preserve_commit_order_supplied = true;
11208 137 break;
11209 2782 case OPT_ENFORCE_GTID_CONSISTENCY: {
11210 const char *wrong_value =
11211
1/2
✓ Branch 0 taken 2782 times.
✗ Branch 1 not taken.
2782 fixup_enforce_gtid_consistency_command_line(argument);
11212
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2778 times.
2782 if (wrong_value != nullptr)
11213
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_INVALID_VALUE_FOR_ENFORCE_GTID_CONSISTENCY,
11214 wrong_value);
11215 2782 } break;
11216 case OPT_NAMED_PIPE_FULL_ACCESS_GROUP:
11217 #ifdef _WIN32
11218 if (!is_valid_named_pipe_full_access_group(argument)) {
11219 LogErr(ERROR_LEVEL, ER_INVALID_NAMED_PIPE_FULL_ACCESS_GROUP);
11220 return 1;
11221 }
11222 #endif // _WIN32
11223 break;
11224 4 case OPT_RELAY_LOG_INFO_FILE:
11225
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 push_deprecated_warn_no_replacement(nullptr, "--relay-log-info-file");
11226 4 break;
11227 5 case OPT_MASTER_INFO_FILE:
11228
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 push_deprecated_warn_no_replacement(nullptr, "--master-info-file");
11229 5 break;
11230 2 case OPT_LOG_BIN_USE_V1_ROW_EVENTS:
11231
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 push_deprecated_warn_no_replacement(nullptr,
11232 "--log-bin-use-v1-row-events");
11233 2 break;
11234 1 case OPT_SLAVE_ROWS_SEARCH_ALGORITHMS:
11235
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr,
11236 "--slave-rows-search-algorithms");
11237 1 break;
11238 57 case OPT_MASTER_INFO_REPOSITORY:
11239
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 push_deprecated_warn_no_replacement(nullptr, "--master-info-repository");
11240 57 break;
11241 260 case OPT_RELAY_LOG_INFO_REPOSITORY:
11242
1/2
✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
260 push_deprecated_warn_no_replacement(nullptr,
11243 "--relay-log-info-repository");
11244 260 break;
11245 100 case OPT_TRANSACTION_WRITE_SET_EXTRACTION:
11246
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 push_deprecated_warn_no_replacement(nullptr,
11247 "--transaction-write-set-extraction");
11248 100 break;
11249 1 case OPT_DISCONNECT_SLAVE_EVENT_COUNT:
11250
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr,
11251 "--disconnect-slave-event-count");
11252 1 break;
11253 1 case OPT_ABORT_SLAVE_EVENT_COUNT:
11254
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--abort-slave-event-count");
11255 1 break;
11256 103 case OPT_REPLICA_PARALLEL_TYPE:
11257
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 push_deprecated_warn_no_replacement(nullptr, "--replica-parallel-type");
11258 103 break;
11259 188 case OPT_REPLICA_PARALLEL_WORKERS:
11260
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 174 times.
188 if (opt_mts_replica_parallel_workers == 0) {
11261
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 push_deprecated_warn(nullptr, "--replica-parallel-workers=0",
11262 "'--replica-parallel-workers=1'");
11263 }
11264 188 break;
11265 1 case OPT_OLD_STYLE_USER_LIMITS:
11266
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--old-style-user-limits");
11267 }
11268 704203 return false;
11269 }
11270
11271 /** Handle arguments for multiple key caches. */
11272
11273 48628 static void *mysql_getopt_value(const char *keyname, size_t key_length,
11274 const struct my_option *option, int *error) {
11275
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 48624 times.
48628 if (error) *error = 0;
11276
1/2
✓ Branch 0 taken 48628 times.
✗ Branch 1 not taken.
48628 switch (option->id) {
11277 48628 case OPT_KEY_BUFFER_SIZE:
11278 case OPT_KEY_CACHE_BLOCK_SIZE:
11279 case OPT_KEY_CACHE_DIVISION_LIMIT:
11280 case OPT_KEY_CACHE_AGE_THRESHOLD: {
11281 KEY_CACHE *key_cache;
11282 97256 if (!(key_cache =
11283
3/6
✓ Branch 0 taken 48628 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48628 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 48628 times.
48628 get_or_create_key_cache(std::string{keyname, key_length}))) {
11284 if (error) *error = EXIT_OUT_OF_MEMORY;
11285 return nullptr;
11286 }
11287
4/5
✓ Branch 0 taken 12160 times.
✓ Branch 1 taken 12156 times.
✓ Branch 2 taken 12156 times.
✓ Branch 3 taken 12156 times.
✗ Branch 4 not taken.
48628 switch (option->id) {
11288 12160 case OPT_KEY_BUFFER_SIZE:
11289 12160 return &key_cache->param_buff_size;
11290 12156 case OPT_KEY_CACHE_BLOCK_SIZE:
11291 12156 return &key_cache->param_block_size;
11292 12156 case OPT_KEY_CACHE_DIVISION_LIMIT:
11293 12156 return &key_cache->param_division_limit;
11294 12156 case OPT_KEY_CACHE_AGE_THRESHOLD:
11295 12156 return &key_cache->param_age_threshold;
11296 }
11297 }
11298 }
11299 return option->value;
11300 }
11301
11302 /**
11303 Get server options from the command line,
11304 and perform related server initializations.
11305 @param [in, out] argc_ptr command line options (count)
11306 @param [in, out] argv_ptr command line options (values)
11307 @return 0 on success
11308
11309 @todo
11310 - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code?
11311 */
11312 12142 static int get_options(int *argc_ptr, char ***argv_ptr) {
11313 int ho_error;
11314
11315 12142 my_getopt_register_get_addr(mysql_getopt_value);
11316
11317 /* prepare all_options array */
11318 12142 all_options.reserve(array_elements(my_long_options));
11319 849940 for (my_option *opt = my_long_options;
11320
2/2
✓ Branch 0 taken 837798 times.
✓ Branch 1 taken 12142 times.
849940 opt < my_long_options + array_elements(my_long_options) - 1; opt++) {
11321 837798 all_options.push_back(*opt);
11322 }
11323 12142 sys_var_add_options(&all_options, sys_var::PARSE_NORMAL);
11324 12142 add_terminator(&all_options);
11325
11326 /* Skip unknown options so that they may be processed later by plugins */
11327 12142 my_getopt_skip_unknown = true;
11328
11329
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 12111 times.
12142 if ((ho_error = handle_options(argc_ptr, argv_ptr, &all_options[0],
11330 mysqld_get_one_option)))
11331 31 return ho_error;
11332
11333 // update suppression list in filter engine
11334 {
11335 int rr;
11336 // try to set the list
11337 12111 if (((rr = log_builtins_filter_parse_suppression_list(
11338
4/4
✓ Branch 0 taken 12109 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 12076 times.
24220 opt_log_error_suppression_list, false)) != 0) ||
11339
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 12076 times.
12109 ((rr = log_builtins_filter_parse_suppression_list(
11340 opt_log_error_suppression_list, true)) != 0)) {
11341 35 rr = -(rr + 1);
11342
7/14
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 35 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 35 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 35 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 35 times.
✗ Branch 13 not taken.
35 LogErr(ERROR_LEVEL, ER_CANT_SET_ERROR_SUPPRESSION_LIST_FROM_COMMAND_LINE,
11343 "log_error_suppression_list", &opt_log_error_suppression_list[rr]);
11344
11345 /*
11346 We were given an illegal value at start-up, so the default will be
11347 used instead. We have reported the problem (and the dodgy value);
11348 let's now point our variable back at the default (i.e. the value
11349 actually used) so SELECT @@GLOBAL.log_error_suppression_list will
11350 render correct results.
11351 */
11352
2/4
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35 sys_var *var = find_static_system_variable("log_error_suppression_list");
11353
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if (var != nullptr) {
11354 35 opt_log_error_suppression_list = (char *)var->get_default();
11355 /*
11356 During unit-testing, the log subsystem is not initialized,
11357 so while the default should always check out as a valid
11358 argument, actually setting it will still fail in this
11359 particular case as we cannot acquire the rule-set or its
11360 lock.
11361 */
11362 35 if (log_builtins_filter_parse_suppression_list(
11363
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 opt_log_error_suppression_list, false) == 0) {
11364 35 log_builtins_filter_parse_suppression_list(
11365 opt_log_error_suppression_list, true);
11366 } else {
11367 assert(false); /* purecov: inspected */
11368 }
11369 }
11370 }
11371 }
11372
11373
2/2
✓ Branch 0 taken 12093 times.
✓ Branch 1 taken 18 times.
12111 if (!is_help_or_validate_option())
11374 12093 vector<my_option>().swap(all_options); // Deletes the vector contents.
11375
11376 /* Add back the program name handle_options removes */
11377 12111 (*argc_ptr)++;
11378 12111 (*argv_ptr)--;
11379
11380 /*
11381 Options have been parsed. Now some of them need additional special
11382 handling, like custom value checking, checking of incompatibilites
11383 between options, setting of multiple variables, etc.
11384 Do them here.
11385 */
11386
11387
11/18
✓ Branch 0 taken 12098 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 12097 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
12111 if (!opt_help && opt_verbose) LogErr(ERROR_LEVEL, ER_VERBOSE_REQUIRES_HELP);
11388
11389
4/4
✓ Branch 0 taken 12101 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 12096 times.
✓ Branch 3 taken 5 times.
12109 if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
11390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12096 times.
12096 opt_log_slow_replica_statements ||
11391
3/4
✓ Branch 0 taken 12109 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12111 times.
36318 global_system_variables.log_query_errors.check_variable_set()) &&
11392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 !opt_slow_log)
11393 LogErr(WARNING_LEVEL, ER_POINTLESS_WITHOUT_SLOWLOG);
11394
11395 12111 if (global_system_variables.net_buffer_length >
11396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 global_system_variables.max_allowed_packet) {
11397 LogErr(WARNING_LEVEL, ER_WASTEFUL_NET_BUFFER_SIZE,
11398 global_system_variables.net_buffer_length,
11399 global_system_variables.max_allowed_packet);
11400 }
11401
11402 /*
11403 TIMESTAMP columns get implicit DEFAULT values when
11404 --explicit_defaults_for_timestamp is not set.
11405 This behavior is deprecated now.
11406 */
11407
4/4
✓ Branch 0 taken 12093 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 12106 times.
24204 if (!is_help_or_validate_option() &&
11408
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12088 times.
12093 !global_system_variables.explicit_defaults_for_timestamp)
11409
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 LogErr(WARNING_LEVEL, ER_DEPRECATED_TIMESTAMP_IMPLICIT_DEFAULTS);
11410
11411 12111 opt_init_connect.length = strlen(opt_init_connect.str);
11412 12111 opt_init_replica.length = strlen(opt_init_replica.str);
11413 12111 opt_mandatory_roles.length = strlen(opt_mandatory_roles.str);
11414
11415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 if (global_system_variables.low_priority_updates)
11416 thr_upgraded_concurrent_insert_lock = TL_WRITE_LOW_PRIORITY;
11417
11418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 if (ft_boolean_check_syntax_string(
11419 pointer_cast<const uchar *>(ft_boolean_syntax))) {
11420 LogErr(ERROR_LEVEL, ER_FT_BOOL_SYNTAX_INVALID, ft_boolean_syntax);
11421 return 1;
11422 }
11423
11424
6/6
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 11794 times.
✓ Branch 2 taken 314 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 314 times.
✓ Branch 5 taken 11797 times.
12111 if (opt_noacl && !is_help_or_validate_option()) opt_disable_networking = true;
11425
11426
2/2
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 11763 times.
12111 if (opt_disable_networking) mysqld_port = 0;
11427
11428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 if (opt_skip_show_db) opt_specialflag |= SPECIAL_SKIP_SHOW_DB;
11429
11430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 if (myisam_flush) flush_time = 0;
11431
11432
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 12079 times.
12111 if (opt_replica_skip_errors) add_replica_skip_errors(opt_replica_skip_errors);
11433
11434
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 if (global_system_variables.max_join_size == HA_POS_ERROR)
11435 12111 global_system_variables.option_bits |= OPTION_BIG_SELECTS;
11436 else
11437 global_system_variables.option_bits &= ~OPTION_BIG_SELECTS;
11438
11439 // Synchronize @@global.autocommit value on --autocommit
11440 12111 const ulonglong turn_bit_on =
11441
2/2
✓ Branch 0 taken 12108 times.
✓ Branch 1 taken 3 times.
12111 opt_autocommit ? OPTION_AUTOCOMMIT : OPTION_NOT_AUTOCOMMIT;
11442 12111 global_system_variables.option_bits =
11443 12111 (global_system_variables.option_bits &
11444 12111 ~(OPTION_NOT_AUTOCOMMIT | OPTION_AUTOCOMMIT)) |
11445 turn_bit_on;
11446
11447 // Synchronize @@global.autocommit metadata on --autocommit
11448 12111 my_option *opt = &my_long_options[3];
11449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 assert(strcmp(opt->name, "autocommit") == 0);
11450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 assert(opt->arg_source != nullptr);
11451 12111 Sys_autocommit_ptr->set_source_name(opt->arg_source->m_path_name);
11452 12111 Sys_autocommit_ptr->set_source(opt->arg_source->m_source);
11453
11454 12111 global_system_variables.sql_mode =
11455 12111 expand_sql_mode(global_system_variables.sql_mode, nullptr);
11456
11457
2/2
✓ Branch 0 taken 12109 times.
✓ Branch 1 taken 2 times.
12111 if (!my_enable_symlinks) have_symlink = SHOW_OPTION_DISABLED;
11458
11459 /* Set global MyISAM variables from delay_key_write_options */
11460 12111 fix_delay_key_write(nullptr, nullptr, OPT_GLOBAL);
11461
11462 #ifndef _WIN32
11463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12111 times.
12111 if (mysqld_chroot) set_root(mysqld_chroot);
11464 #endif
11465
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12108 times.
12111 if (fix_paths()) return 1;
11466
11467 /*
11468 Set some global variables from the global_system_variables
11469 In most cases the global variables will not be used
11470 */
11471 12108 my_disable_locking = myisam_single_user = (opt_external_locking == 0);
11472 12108 my_default_record_cache_size = global_system_variables.read_buff_size;
11473
11474 12108 global_system_variables.long_query_time =
11475 12108 (ulonglong)(global_system_variables.long_query_time_double * 1e6);
11476
11477 12108 init_log_slow_verbosity();
11478 12108 init_slow_query_log_use_global_control();
11479 12108 init_log_slow_sp_statements();
11480
11481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (opt_short_log_format) opt_specialflag |= SPECIAL_SHORT_LOG_FORMAT;
11482
11483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (Connection_handler_manager::init()) {
11484 LogErr(ERROR_LEVEL, ER_CONNECTION_HANDLING_OOM);
11485 return 1;
11486 }
11487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12108 times.
12108 if (Global_THD_manager::create_instance()) {
11488 LogErr(ERROR_LEVEL, ER_THREAD_HANDLING_OOM);
11489 return 1;
11490 }
11491
11492 /* If --super-read-only was specified, set read_only to 1 */
11493
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12102 times.
12108 read_only = super_read_only ? super_read_only : read_only;
11494 12108 opt_readonly = read_only;
11495
11496 12108 return 0;
11497 12108 }
11498
11499 /*
11500 Create version name for running mysqld version
11501 We automatically add suffixes -debug, -valgrind, -asan, -ubsan
11502 to the version name to make the version more descriptive.
11503 (MYSQL_SERVER_SUFFIX is set by the compilation environment)
11504 */
11505
11506 /*
11507 The following code is quite ugly as there is no portable way to easily set a
11508 string to the value of a macro
11509 */
11510 #ifdef MYSQL_SERVER_SUFFIX
11511 #define MYSQL_SERVER_SUFFIX_STR STRINGIFY_ARG(MYSQL_SERVER_SUFFIX)
11512 #else
11513 #define MYSQL_SERVER_SUFFIX_STR MYSQL_SERVER_SUFFIX_DEF
11514 #endif
11515
11516 12122 static void set_server_version(void) {
11517 12122 char *end [[maybe_unused]] = strxmov(server_version, MYSQL_SERVER_VERSION,
11518 MYSQL_SERVER_SUFFIX_STR, NullS);
11519 #ifndef NDEBUG
11520
1/2
✓ Branch 0 taken 12122 times.
✗ Branch 1 not taken.
12122 if (!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug"))
11521 12122 end = my_stpcpy(end, "-debug");
11522 #endif
11523 #ifdef HAVE_VALGRIND
11524 if (SERVER_VERSION_LENGTH - (end - server_version) >
11525 static_cast<int>(sizeof("-valgrind")))
11526 end = my_stpcpy(end, "-valgrind");
11527 #endif
11528 #ifdef HAVE_ASAN
11529 if (SERVER_VERSION_LENGTH - (end - server_version) >
11530 static_cast<int>(sizeof("-asan")))
11531 end = my_stpcpy(end, "-asan");
11532 #endif
11533 #ifdef HAVE_LSAN
11534 if (SERVER_VERSION_LENGTH - (end - server_version) >
11535 static_cast<int>(sizeof("-lsan")))
11536 end = my_stpcpy(end, "-lsan");
11537 #endif
11538 #ifdef HAVE_UBSAN
11539 if (SERVER_VERSION_LENGTH - (end - server_version) >
11540 static_cast<int>(sizeof("-ubsan")))
11541 end = my_stpcpy(end, "-ubsan");
11542 #endif
11543 #ifdef HAVE_TSAN
11544 if (SERVER_VERSION_LENGTH - (end - server_version) >
11545 static_cast<int>(sizeof("-tsan")))
11546 end = my_stpcpy(end, "-tsan");
11547 #endif
11548
11549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12122 times.
12122 assert(end < server_version + SERVER_VERSION_LENGTH);
11550 12122 my_stpcpy(server_version_suffix,
11551 server_version + strlen(MYSQL_SERVER_VERSION));
11552 12122 }
11553
11554 36373 static const char *get_relative_path(const char *path) {
11555
3/6
✓ Branch 0 taken 36373 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36373 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36373 times.
✗ Branch 5 not taken.
36373 if (test_if_hard_path(path) && is_prefix(path, DEFAULT_MYSQL_HOME) &&
11556 strcmp(DEFAULT_MYSQL_HOME, FN_ROOTDIR)) {
11557 36373 path += strlen(DEFAULT_MYSQL_HOME);
11558
2/2
✓ Branch 0 taken 36373 times.
✓ Branch 1 taken 36373 times.
72746 while (is_directory_separator(*path)) path++;
11559 }
11560 36373 return path;
11561 }
11562
11563 73799 static bool is_secure_path(const char *path, const char *opt_base) {
11564 char buff1[FN_REFLEN], buff2[FN_REFLEN];
11565 size_t opt_base_len;
11566 /*
11567 All paths are secure if opt_base is 0
11568 */
11569
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 73585 times.
73799 if (!opt_base[0]) return true;
11570
11571 73585 opt_base_len = strlen(opt_base);
11572
11573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73585 times.
73585 if (strlen(path) >= FN_REFLEN) return false;
11574
11575
3/4
✓ Branch 0 taken 73585 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 73578 times.
73585 if (!my_strcasecmp(system_charset_info, opt_base, "NULL")) return false;
11576
11577
3/4
✓ Branch 0 taken 73578 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25518 times.
✓ Branch 3 taken 48060 times.
73578 if (my_realpath(buff1, path, 0)) {
11578 /*
11579 The supplied file path might have been a file and not a directory.
11580 */
11581
1/2
✓ Branch 0 taken 25518 times.
✗ Branch 1 not taken.
25518 int length = (int)dirname_length(path);
11582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25518 times.
25518 if (length >= FN_REFLEN) return false;
11583 25518 memcpy(buff2, path, length);
11584 25518 buff2[length] = '\0';
11585
6/8
✓ Branch 0 taken 25518 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25518 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 25500 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 25500 times.
25518 if (length == 0 || my_realpath(buff1, buff2, 0)) return false;
11586 }
11587
1/2
✓ Branch 0 taken 73560 times.
✗ Branch 1 not taken.
73560 convert_dirname(buff2, buff1, NullS);
11588
1/2
✓ Branch 0 taken 73560 times.
✗ Branch 1 not taken.
73560 if (!lower_case_file_system) {
11589
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 73529 times.
73560 if (strncmp(opt_base, buff2, opt_base_len)) return false;
11590 } else {
11591 if (files_charset_info->coll->strnncoll(
11592 files_charset_info, (uchar *)buff2, strlen(buff2),
11593 pointer_cast<const uchar *>(opt_base), opt_base_len, true))
11594 return false;
11595 }
11596 73529 return true;
11597 }
11598
11599 /**
11600 Test a file path to determine if the path is compatible with the secure file
11601 path restriction.
11602
11603 @param path null terminated character string
11604
11605 @retval true The path is secure
11606 @retval false The path isn't secure
11607 */
11608 73694 bool is_secure_file_path(const char *path) {
11609 73694 return is_secure_path(path, opt_secure_file_priv);
11610 }
11611
11612 /**
11613 Test a file path to determine if the path is compatible with the secure log
11614 path restriction.
11615
11616 @param path null terminated character string
11617
11618 @retval true The path is secure
11619 @retval false The path isn't secure
11620 */
11621 105 bool is_secure_log_path(const char *path) {
11622 105 return is_secure_path(path, opt_secure_log_path);
11623 }
11624
11625 /**
11626 check_secure_file_priv_path : Checks path specified through
11627 --secure-file-priv and raises warning in following cases:
11628 1. If path is empty string or NULL and mysqld is not running
11629 with --initialize (bootstrap mode).
11630 2. If path can access data directory
11631 3. If path points to a directory which is accessible by
11632 all OS users (non-Windows build only)
11633
11634 It throws error in following cases:
11635
11636 1. If path normalization fails
11637 2. If it can not get stats of the directory
11638
11639 Assumptions :
11640 1. Data directory path has been normalized
11641 2. opt_secure_file_priv has been normalized unless it is set
11642 to "NULL".
11643
11644 @returns Status of validation
11645 @retval true : Validation is successful with/without warnings
11646 @retval false : Validation failed. Error is raised.
11647 */
11648
11649 24190 static bool check_secure_path(const char *opt_var, const char *variable_name,
11650 int warn_empty_err) {
11651 24190 char datadir_buffer[FN_REFLEN + 1] = {0};
11652 24190 char plugindir_buffer[FN_REFLEN + 1] = {0};
11653 24190 char whichdir[20] = {0};
11654 24190 size_t opt_plugindir_len = 0;
11655 24190 size_t opt_datadir_len = 0;
11656 24190 size_t opt_var_len = 0;
11657 24190 bool warn = false;
11658 bool case_insensitive_fs;
11659 #ifndef _WIN32
11660 MY_STAT dir_stat;
11661 #endif
11662
11663
2/2
✓ Branch 0 taken 12645 times.
✓ Branch 1 taken 11545 times.
24190 if (!opt_var[0]) {
11664
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 12045 times.
12645 if (opt_initialize) {
11665 /*
11666 Do not impose --secure-file-priv restriction
11667 in bootstrap mode
11668 */
11669
8/16
✓ Branch 0 taken 600 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 600 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 600 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 600 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 600 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 600 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 600 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 600 times.
✗ Branch 15 not taken.
600 LogErr(INFORMATION_LEVEL, ER_SEC_FILE_PRIV_IGNORED, variable_name);
11670 } else {
11671
8/16
✓ Branch 0 taken 12045 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12045 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12045 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12045 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12045 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12045 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12045 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12045 times.
✗ Branch 15 not taken.
12045 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_EMPTY, variable_name);
11672 }
11673 12645 return true;
11674 }
11675
11676 /*
11677 Setting --secure-file-priv to NULL would disable
11678 reading/writing from/to file
11679 */
11680
3/4
✓ Branch 0 taken 11545 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 11497 times.
11545 if (!my_strcasecmp(system_charset_info, opt_var, "NULL")) {
11681
8/16
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 48 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 48 times.
✗ Branch 15 not taken.
48 LogErr(INFORMATION_LEVEL, warn_empty_err, variable_name);
11682 48 return true;
11683 }
11684
11685 /*
11686 Check if --secure-file-priv can access data directory
11687 */
11688 11497 opt_var_len = strlen(opt_var);
11689
11690 /*
11691 Adds dir separator at the end.
11692 This is required in subsequent comparison
11693 */
11694
1/2
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
11497 convert_dirname(datadir_buffer, mysql_unpacked_real_data_home, NullS);
11695 11497 opt_datadir_len = strlen(datadir_buffer);
11696
11697
1/2
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
11497 case_insensitive_fs = (test_if_case_insensitive(datadir_buffer) == 1);
11698
11699
1/2
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
11497 if (!case_insensitive_fs) {
11700
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11497 times.
✓ Branch 2 taken 11025 times.
✓ Branch 3 taken 472 times.
11497 if (!strncmp(
11701 datadir_buffer, opt_var,
11702 opt_datadir_len < opt_var_len ? opt_datadir_len : opt_var_len)) {
11703 11025 warn = true;
11704 11025 strcpy(whichdir, "Data directory");
11705 }
11706 } else {
11707 if (!files_charset_info->coll->strnncoll(
11708 files_charset_info, (uchar *)datadir_buffer, opt_datadir_len,
11709 pointer_cast<const uchar *>(opt_var), opt_var_len, true)) {
11710 warn = true;
11711 strcpy(whichdir, "Data directory");
11712 }
11713 }
11714
11715 /*
11716 Don't bother comparing --secure-file-priv with --plugin-dir
11717 if we already have a match against --datdir or
11718 --plugin-dir is not pointing to a valid directory.
11719 */
11720
6/8
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 11025 times.
✓ Branch 2 taken 472 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 472 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 472 times.
✓ Branch 7 taken 11025 times.
11497 if (!warn && !my_realpath(plugindir_buffer, opt_plugin_dir, 0)) {
11721
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 convert_dirname(plugindir_buffer, plugindir_buffer, NullS);
11722 472 opt_plugindir_len = strlen(plugindir_buffer);
11723
11724
1/2
✓ Branch 0 taken 472 times.
✗ Branch 1 not taken.
472 if (!case_insensitive_fs) {
11725
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 471 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 471 times.
472 if (!strncmp(plugindir_buffer, opt_var,
11726 opt_plugindir_len < opt_var_len ? opt_plugindir_len
11727 : opt_var_len)) {
11728 1 warn = true;
11729 1 strcpy(whichdir, "Plugin directory");
11730 }
11731 } else {
11732 if (!files_charset_info->coll->strnncoll(
11733 files_charset_info, (uchar *)plugindir_buffer, opt_plugindir_len,
11734 pointer_cast<const uchar *>(opt_var), opt_var_len, true)) {
11735 warn = true;
11736 strcpy(whichdir, "Plugin directory");
11737 }
11738 }
11739 }
11740
11741
2/2
✓ Branch 0 taken 11026 times.
✓ Branch 1 taken 471 times.
11497 if (warn)
11742
8/16
✓ Branch 0 taken 11026 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11026 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11026 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11026 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11026 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11026 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11026 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 11026 times.
✗ Branch 15 not taken.
11026 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_DIRECTORY_INSECURE, variable_name,
11743 whichdir, variable_name);
11744
11745 #ifndef _WIN32
11746 /*
11747 Check for --secure-file-priv directory's permission
11748 */
11749
2/4
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11497 times.
11497 if (!(my_stat(opt_var, &dir_stat, MYF(0)))) {
11750 LogErr(ERROR_LEVEL, ER_SEC_FILE_PRIV_CANT_STAT, variable_name);
11751 return false;
11752 }
11753
11754
1/2
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
11497 if (dir_stat.st_mode & S_IRWXO)
11755
8/16
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11497 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11497 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11497 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11497 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11497 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11497 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 11497 times.
✗ Branch 15 not taken.
11497 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_DIRECTORY_PERMISSIONS,
11756 variable_name);
11757 #endif
11758 11497 return true;
11759 }
11760
11761 /**
11762 check_secure_file_priv_path : Checks path specified through
11763 --secure-file-priv and raises warning in following cases:
11764 1. If path is empty string or NULL and mysqld is not running
11765 with --initialize (bootstrap mode).
11766 2. If path can access data directory
11767 3. If path points to a directory which is accessible by
11768 all OS users (non-Windows build only)
11769
11770 It throws error in following cases:
11771
11772 1. If path normalization fails
11773 2. If it can not get stats of the directory
11774
11775 Assumptions :
11776 1. Data directory path has been normalized
11777 2. opt_secure_file_priv has been normalized unless it is set
11778 to "NULL".
11779
11780 @returns Status of validation
11781 @retval true : Validation is successful with/without warnings
11782 @retval false : Validation failed. Error is raised.
11783 */
11784
11785 12095 static bool check_secure_file_priv_path() {
11786 12095 return check_secure_path(opt_secure_file_priv, "secure-file-priv",
11787 12095 ER_SEC_FILE_PRIV_NULL);
11788 }
11789
11790 12095 static bool check_secure_log_path() {
11791 12095 return check_secure_path(opt_secure_log_path, "secure-log-path",
11792 12095 ER_SEC_LOG_PATH_NULL);
11793 }
11794
11795 #ifdef WIN32
11796 // check_tmpdir_path_lengths returns true if all paths are valid,
11797 // false if any path is too long.
11798 static bool check_tmpdir_path_lengths(const MY_TMPDIR &tmpdir_list) {
11799 const size_t max_tmpdir_len = MAX_PATH - MY_MAX_TEMP_FILENAME_LEN;
11800 bool result = true;
11801 for (uint i = 0; i <= tmpdir_list.max; i++) {
11802 std::string tmpdir_entry(tmpdir_list.list[i]);
11803 const int path_separator_reqd =
11804 is_directory_separator(tmpdir_entry.back()) ? 0 : 1;
11805 if ((tmpdir_entry.length() + path_separator_reqd) > max_tmpdir_len) {
11806 LogErr(ERROR_LEVEL, ER_TMPDIR_PATH_TOO_LONG, tmpdir_list.list[i],
11807 max_tmpdir_len, MY_MAX_TEMP_FILENAME_LEN);
11808 result = false;
11809 }
11810 }
11811 return result;
11812 }
11813 #endif
11814
11815 24191 static int fix_secure_path(const char *&opt_path, char *realpath,
11816 const char *variable_name) {
11817 24191 bool opt_nonempty = false;
11818 /*
11819 Convert the secure-file-priv/secure-log-path option to system format,
11820 allowing a quick strcmp to check if read or write is in an allowed dir
11821 */
11822
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 23591 times.
24191 if (opt_initialize) opt_path = "";
11823 24191 opt_nonempty = opt_path[0] ? true : false;
11824
11825
3/4
✓ Branch 0 taken 11546 times.
✓ Branch 1 taken 12645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11546 times.
24191 if (opt_nonempty && strlen(opt_path) > FN_REFLEN) {
11826 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_ARGUMENT_TOO_LONG, variable_name,
11827 FN_REFLEN - 1);
11828 return 1;
11829 }
11830
11831 24191 char buff[FN_REFLEN] = {
11832 0,
11833 };
11834
7/8
✓ Branch 0 taken 11546 times.
✓ Branch 1 taken 12645 times.
✓ Branch 2 taken 11546 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11498 times.
✓ Branch 5 taken 48 times.
✓ Branch 6 taken 11498 times.
✓ Branch 7 taken 12693 times.
24191 if (opt_nonempty && my_strcasecmp(system_charset_info, opt_path, "NULL")) {
11835
1/2
✓ Branch 0 taken 11498 times.
✗ Branch 1 not taken.
11498 int retval = my_realpath(buff, opt_path, MYF(MY_WME));
11836
2/2
✓ Branch 0 taken 11497 times.
✓ Branch 1 taken 1 times.
11498 if (!retval) {
11837
1/2
✓ Branch 0 taken 11497 times.
✗ Branch 1 not taken.
11497 convert_dirname(realpath, buff, NullS);
11838 #ifdef WIN32
11839 MY_DIR *dir = my_dir(realpath, MYF(MY_DONT_SORT + MY_WME));
11840 if (!dir) {
11841 retval = 1;
11842 } else {
11843 my_dirend(dir);
11844 }
11845 #endif
11846 }
11847
11848
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11497 times.
11498 if (retval) {
11849
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_SEC_FILE_PRIV_CANT_ACCESS_DIR, variable_name,
11850 opt_path);
11851 1 return 1;
11852 }
11853 11497 opt_path = realpath;
11854 }
11855
11856 24190 return 0;
11857 }
11858
11859 12111 static int fix_paths(void) {
11860 char buff[FN_REFLEN];
11861
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(mysql_home, mysql_home, NullS);
11862 /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */
11863
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 my_realpath(mysql_home, mysql_home, MYF(0));
11864 /* Ensure that mysql_home ends in FN_LIBCHAR */
11865 12111 char *pos = strend(mysql_home);
11866
3/4
✓ Branch 0 taken 12059 times.
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 12059 times.
✗ Branch 3 not taken.
12111 if (pos == mysql_home || pos[-1] != FN_LIBCHAR) {
11867 12111 pos[0] = FN_LIBCHAR;
11868 12111 pos[1] = 0;
11869 }
11870
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(lc_messages_dir, lc_messages_dir, NullS);
11871
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(mysql_real_data_home, mysql_real_data_home, NullS);
11872
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(mysql_home, mysql_home, ""); // Resolve current dir
11873
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(mysql_real_data_home, mysql_real_data_home, mysql_home);
11874
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(pidfile_name, pidfile_name_ptr, mysql_real_data_home);
11875
11876
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(
11877 opt_plugin_dir,
11878
3/4
✓ Branch 0 taken 6069 times.
✓ Branch 1 taken 6042 times.
✓ Branch 2 taken 6069 times.
✗ Branch 3 not taken.
12111 opt_plugin_dir_ptr ? opt_plugin_dir_ptr : get_relative_path(PLUGINDIR),
11879 NullS);
11880
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(opt_plugin_dir, opt_plugin_dir, mysql_home);
11881 12111 opt_plugin_dir_ptr = opt_plugin_dir;
11882
11883
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
11884 12111 mysql_unpacked_real_data_home_len = strlen(mysql_unpacked_real_data_home);
11885
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 11994 times.
12111 if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len - 1] ==
11886 FN_LIBCHAR)
11887 117 --mysql_unpacked_real_data_home_len;
11888
11889
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 const char *sharedir = get_relative_path(SHAREDIR);
11890
2/4
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12111 times.
12111 if (test_if_hard_path(sharedir))
11891 strmake(buff, sharedir, sizeof(buff) - 1); /* purecov: tested */
11892 else
11893
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 strxnmov(buff, sizeof(buff) - 1, mysql_home, sharedir, NullS);
11894
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(buff, buff, NullS);
11895
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(lc_messages_dir, lc_messages_dir, buff);
11896
11897 /* If --character-sets-dir isn't given, use shared library dir */
11898
2/2
✓ Branch 0 taken 11676 times.
✓ Branch 1 taken 435 times.
12111 if (charsets_dir)
11899
1/2
✓ Branch 0 taken 11676 times.
✗ Branch 1 not taken.
11676 strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir) - 1);
11900 else
11901
1/2
✓ Branch 0 taken 435 times.
✗ Branch 1 not taken.
435 strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir) - 1, buff,
11902 CHARSET_DIR, NullS);
11903
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 (void)my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
11904
1/2
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
12111 convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
11905 12111 charsets_dir = mysql_charsets_dir;
11906
11907
3/4
✓ Branch 0 taken 12111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 12109 times.
12111 if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) return 1;
11908 #ifdef WIN32
11909 if (!check_tmpdir_path_lengths(mysql_tmpdir_list)) return 1;
11910 #endif
11911
3/4
✓ Branch 0 taken 433 times.
✓ Branch 1 taken 11676 times.
✓ Branch 2 taken 433 times.
✗ Branch 3 not taken.
12109 if (!opt_mysql_tmpdir) opt_mysql_tmpdir = mysql_tmpdir;
11912
3/4
✓ Branch 0 taken 8936 times.
✓ Branch 1 taken 3173 times.
✓ Branch 2 taken 8936 times.
✗ Branch 3 not taken.
12109 if (!replica_load_tmpdir) replica_load_tmpdir = mysql_tmpdir;
11913
11914
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 12096 times.
12109 if (opt_help) return 0;
11915
11916
3/4
✓ Branch 0 taken 12096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 12095 times.
12096 if (fix_secure_path(opt_secure_file_priv, secure_file_real_path,
11917 "secure-file-priv"))
11918 1 return 1;
11919
2/4
✓ Branch 0 taken 12095 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12095 times.
12095 if (!check_secure_file_priv_path()) return 1;
11920
11921
2/4
✓ Branch 0 taken 12095 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12095 times.
12095 if (fix_secure_path(opt_secure_log_path, secure_log_real_path,
11922 "secure-log-path"))
11923 return 1;
11924
2/4
✓ Branch 0 taken 12095 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12095 times.
12095 if (!check_secure_log_path()) return 1;
11925
11926 12095 return 0;
11927 }
11928
11929 /**
11930 Check if file system used for databases is case insensitive.
11931
11932 @param dir_name Directory to test
11933
11934 @retval
11935 -1 Don't know (Test failed)
11936 @retval
11937 0 File system is case sensitive
11938 @retval
11939 1 File system is case insensitive
11940 */
11941
11942 23594 static int test_if_case_insensitive(const char *dir_name) {
11943 23594 int result = 0;
11944 File file;
11945 char buff[FN_REFLEN], buff2[FN_REFLEN];
11946 MY_STAT stat_info;
11947 23594 const char *const tmp_file_name = "mysqld_tmp_file_case_insensitive_test";
11948
1/2
✓ Branch 0 taken 23594 times.
✗ Branch 1 not taken.
23594 DBUG_TRACE;
11949
11950
1/2
✓ Branch 0 taken 23594 times.
✗ Branch 1 not taken.
23594 fn_format(buff, tmp_file_name, dir_name, ".lower-test",
11951 MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
11952
1/2
✓ Branch 0 taken 23594 times.
✗ Branch 1 not taken.
23594 fn_format(buff2, tmp_file_name, dir_name, ".LOWER-TEST",
11953 MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
11954
1/2
✓ Branch 0 taken 23594 times.
✗ Branch 1 not taken.
23594 mysql_file_delete(key_file_casetest, buff2, MYF(0));
11955
1/2
✓ Branch 0 taken 23594 times.
✗ Branch 1 not taken.
23594 if ((file = mysql_file_create(key_file_casetest, buff, 0666, O_RDWR,
11956
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 23578 times.
23594 MYF(0))) < 0) {
11957
8/16
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 16 times.
✗ Branch 15 not taken.
16 LogErr(WARNING_LEVEL, ER_CANT_CREATE_TEST_FILE, buff);
11958 16 return -1;
11959 }
11960
1/2
✓ Branch 0 taken 23578 times.
✗ Branch 1 not taken.
23578 mysql_file_close(file, MYF(0));
11961
2/4
✓ Branch 0 taken 23578 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23578 times.
23578 if (mysql_file_stat(key_file_casetest, buff2, &stat_info, MYF(0)))
11962 result = 1; // Can access file
11963
1/2
✓ Branch 0 taken 23578 times.
✗ Branch 1 not taken.
23578 mysql_file_delete(key_file_casetest, buff, MYF(MY_WME));
11964
3/8
✓ Branch 0 taken 23578 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23578 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 23578 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
23578 DBUG_PRINT("exit", ("result: %d", result));
11965 23578 return result;
11966 23594 }
11967
11968 /**
11969 Create file to store pid number.
11970 */
11971 11443 static bool create_pid_file() {
11972 File file;
11973 11443 bool check_parent_path = true, is_path_accessible = true;
11974 11443 char pid_filepath[FN_REFLEN], *pos = nullptr;
11975 /* Copy pid file name to get pid file path */
11976 11443 strcpy(pid_filepath, pidfile_name);
11977
11978 /* Iterate through the entire path to check if even one of the sub-dirs
11979 is world-writable */
11980
7/8
✓ Branch 0 taken 114121 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 114121 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102732 times.
✓ Branch 5 taken 11389 times.
✓ Branch 6 taken 102732 times.
✓ Branch 7 taken 11443 times.
114175 while (check_parent_path && (pos = strrchr(pid_filepath, FN_LIBCHAR)) &&
11981 (pos != pid_filepath)) /* shouldn't check root */
11982 {
11983 102732 *pos = '\0'; /* Trim the inner-most dir */
11984
3/7
✓ Branch 0 taken 102732 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 102678 times.
✗ Branch 6 not taken.
102732 switch (is_file_or_dir_world_writable(pid_filepath)) {
11985 case -2:
11986 is_path_accessible = false;
11987 break;
11988 case -1:
11989 LogErr(ERROR_LEVEL, ER_CANT_CHECK_PID_PATH, strerror(errno));
11990 exit(MYSQLD_ABORT_EXIT);
11991 54 case 1:
11992
8/16
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 54 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 54 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 54 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 54 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 54 times.
✗ Branch 15 not taken.
54 LogErr(WARNING_LEVEL, ER_PID_FILE_PRIV_DIRECTORY_INSECURE,
11993 pid_filepath);
11994 54 check_parent_path = false;
11995 54 break;
11996 102678 case 0:
11997 102678 continue; /* Keep checking the parent dir */
11998 }
11999 }
12000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11443 times.
11443 if (!is_path_accessible) {
12001 LogErr(WARNING_LEVEL, ER_PID_FILEPATH_LOCATIONS_INACCESSIBLE);
12002 }
12003
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 if ((file = mysql_file_create(key_file_pid, pidfile_name, 0664,
12004
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) {
12005 char buff[MAX_BIGINT_WIDTH + 1], *end;
12006
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 end = longlong10_to_str(getpid(), buff, -10);
12007 11443 *end++ = '\n';
12008
2/4
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11443 times.
✗ Branch 3 not taken.
11443 if (!mysql_file_write(file, (uchar *)buff, (uint)(end - buff),
12009 MYF(MY_WME | MY_NABP))) {
12010
1/2
✓ Branch 0 taken 11443 times.
✗ Branch 1 not taken.
11443 mysql_file_close(file, MYF(0));
12011 11443 pid_file_created = true;
12012 11443 return false;
12013 }
12014 mysql_file_close(file, MYF(0));
12015 }
12016 LogErr(ERROR_LEVEL, ER_CANT_CREATE_PID_FILE, strerror(errno));
12017 return true;
12018 }
12019
12020 /**
12021 Remove the process' pid file.
12022
12023 @param flags file operation flags
12024 */
12025
12026 10525 static void delete_pid_file(myf flags) {
12027 File file;
12028
6/6
✓ Branch 0 taken 10220 times.
✓ Branch 1 taken 305 times.
✓ Branch 2 taken 9829 times.
✓ Branch 3 taken 391 times.
✓ Branch 4 taken 696 times.
✓ Branch 5 taken 9829 times.
20354 if (opt_initialize || !pid_file_created ||
12029
2/4
✓ Branch 0 taken 9829 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9829 times.
9829 !(file = mysql_file_open(key_file_pid, pidfile_name, O_RDONLY, flags)))
12030 696 return;
12031
12032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9829 times.
9829 if (file == -1) {
12033 LogErr(INFORMATION_LEVEL, ER_CANT_REMOVE_PID_FILE, strerror(errno));
12034 return;
12035 }
12036
12037 uchar buff[MAX_BIGINT_WIDTH + 1];
12038 /* Make sure that the pid file was created by the same process. */
12039
1/2
✓ Branch 0 taken 9829 times.
✗ Branch 1 not taken.
9829 size_t error = mysql_file_read(file, buff, sizeof(buff), flags);
12040
1/2
✓ Branch 0 taken 9829 times.
✗ Branch 1 not taken.
9829 mysql_file_close(file, flags);
12041 9829 buff[sizeof(buff) - 1] = '\0';
12042
3/6
✓ Branch 0 taken 9829 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9829 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9829 times.
✗ Branch 5 not taken.
9829 if (error != MY_FILE_ERROR && atol((char *)buff) == (long)getpid()) {
12043
1/2
✓ Branch 0 taken 9829 times.
✗ Branch 1 not taken.
9829 mysql_file_delete(key_file_pid, pidfile_name, flags);
12044 9829 pid_file_created = false;
12045 }
12046 9829 return;
12047 }
12048
12049 /**
12050 Delete mysql.ibd after aborting upgrade.
12051 */
12052 18 static void delete_dictionary_tablespace() {
12053 char path[FN_REFLEN + 1];
12054 bool not_used;
12055
12056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 build_table_filename(path, sizeof(path) - 1, "", "mysql", ".ibd", 0,
12057 &not_used);
12058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 (void)mysql_file_delete(key_file_misc, path, MYF(MY_WME));
12059
12060 // Drop file which tracks progress of upgrade.
12061
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 dd::upgrade_57::Upgrade_status().remove();
12062 18 }
12063
12064 /**
12065 Returns the current state of the server : booting, operational or shutting
12066 down.
12067
12068 @return
12069 SERVER_BOOTING Server is not operational. It is starting.
12070 SERVER_OPERATING Server is fully initialized and operating.
12071 SERVER_SHUTTING_DOWN Server is shutting down.
12072 */
12073 183941 enum_server_operational_state get_server_state() {
12074 183941 return server_operational_state;
12075 }
12076
12077 /**
12078 Reset status for all threads.
12079 */
12080 class Reset_thd_status : public Do_THD_Impl {
12081 public:
12082 Reset_thd_status() = default;
12083 12467 void operator()(THD *thd) override {
12084 /* Update the global status if not done so already. */
12085
1/2
✓ Branch 0 taken 12467 times.
✗ Branch 1 not taken.
12467 if (!thd->status_var_aggregated) {
12086 12467 add_to_status(&global_status_var, &thd->status_var);
12087 }
12088 12467 reset_system_status_vars(&thd->status_var);
12089 12467 }
12090 };
12091
12092 /**
12093 Reset global and session status variables.
12094 */
12095 3845 void refresh_status() {
12096
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 mysql_mutex_lock(&LOCK_status);
12097
12098 /* For all threads, add status to global status and then reset. */
12099 3845 Reset_thd_status reset_thd_status;
12100
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 Global_THD_manager::get_instance()->do_for_all_thd_copy(&reset_thd_status);
12101 /* net_buffer_length does not accumulate the historical values */
12102 3845 global_status_var.net_buffer_length = 0ULL;
12103 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
12104 /* Reset aggregated status counters. */
12105
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 reset_pfs_status_stats();
12106 #endif
12107
12108 /* Reset some global variables. */
12109
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 reset_status_vars();
12110
12111 /* Reset the counters of all key caches (default and named). */
12112
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 process_key_caches(reset_key_cache_counters);
12113 3845 flush_status_time = time((time_t *)nullptr);
12114
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 mysql_mutex_unlock(&LOCK_status);
12115
12116 /*
12117 Set max_used_connections to the number of currently open
12118 connections. Do this out of LOCK_status to avoid deadlocks.
12119 Status reset becomes not atomic, but status data is not exact anyway.
12120 */
12121
1/2
✓ Branch 0 taken 3845 times.
✗ Branch 1 not taken.
3845 Connection_handler_manager::reset_max_used_connections();
12122 3845 }
12123
12124 class Do_THD_reset_status : public Do_THD_Impl {
12125 public:
12126 591 Do_THD_reset_status() {}
12127 1291 void operator()(THD *thd) override {
12128 1291 PSI_thread *thread = thd->get_psi();
12129
2/2
✓ Branch 0 taken 700 times.
✓ Branch 1 taken 591 times.
1291 if (thread != nullptr) {
12130 /*
12131 During this call,
12132 - inspecting the THD associated with the performance schema
12133 thread instrumentation,
12134 - inspecting the THD status variable
12135 is safe, because the call is protected
12136 by Global_THD_manager::do_for_all_thd(),
12137 so the THD will not be destroyed during the iteration.
12138 */
12139 700 PSI_THREAD_CALL(aggregate_thread_status)(thread);
12140 }
12141 1291 }
12142 };
12143
12144 591 void reset_status_by_thd() {
12145 591 Do_THD_reset_status doit;
12146
1/2
✓ Branch 0 taken 591 times.
✗ Branch 1 not taken.
591 Global_THD_manager::get_instance()->do_for_all_thd(&doit);
12147 591 }
12148
12149 /*****************************************************************************
12150 Instantiate variables for missing storage engines
12151 This section should go away soon
12152 *****************************************************************************/
12153
12154 #ifdef HAVE_PSI_INTERFACE
12155 PSI_mutex_key key_LOCK_tc;
12156 PSI_mutex_key key_hash_filo_lock;
12157 PSI_mutex_key key_LOCK_error_log;
12158 PSI_mutex_key key_LOCK_thd_data;
12159 PSI_mutex_key key_LOCK_thd_sysvar;
12160 PSI_mutex_key key_LOCK_thd_protocol;
12161 PSI_mutex_key key_LOCK_thd_security_ctx;
12162 PSI_mutex_key key_LOG_LOCK_log;
12163 PSI_mutex_key key_source_info_data_lock;
12164 PSI_mutex_key key_source_info_run_lock;
12165 PSI_mutex_key key_source_info_sleep_lock;
12166 PSI_mutex_key key_source_info_thd_lock;
12167 PSI_mutex_key key_source_info_rotate_lock;
12168 PSI_mutex_key key_mutex_replica_reporting_capability_err_lock;
12169 PSI_mutex_key key_relay_log_info_data_lock;
12170 PSI_mutex_key key_relay_log_info_sleep_lock;
12171 PSI_mutex_key key_relay_log_info_thd_lock;
12172 PSI_mutex_key key_relay_log_info_log_space_lock;
12173 PSI_mutex_key key_relay_log_info_run_lock;
12174 PSI_mutex_key key_mutex_slave_parallel_pend_jobs;
12175 PSI_mutex_key key_mutex_slave_parallel_worker_count;
12176 PSI_mutex_key key_mutex_slave_parallel_worker;
12177 PSI_mutex_key key_structure_guard_mutex;
12178 PSI_mutex_key key_TABLE_SHARE_LOCK_ha_data;
12179 PSI_mutex_key key_LOCK_query_plan;
12180 PSI_mutex_key key_LOCK_thd_query;
12181 PSI_mutex_key key_LOCK_cost_const;
12182 PSI_mutex_key key_LOCK_current_cond;
12183 PSI_mutex_key key_LOCK_temporary_tables;
12184 PSI_mutex_key key_LOCK_global_user_client_stats;
12185 PSI_mutex_key key_LOCK_global_table_stats;
12186 PSI_mutex_key key_LOCK_global_index_stats;
12187 PSI_mutex_key key_RELAYLOG_LOCK_commit;
12188 PSI_mutex_key key_RELAYLOG_LOCK_index;
12189 PSI_mutex_key key_RELAYLOG_LOCK_log;
12190 PSI_mutex_key key_RELAYLOG_LOCK_log_end_pos;
12191 PSI_mutex_key key_RELAYLOG_LOCK_sync;
12192 PSI_mutex_key key_RELAYLOG_LOCK_xids;
12193 PSI_mutex_key key_gtid_ensure_index_mutex;
12194 PSI_mutex_key key_object_cache_mutex; // TODO need to initialize
12195 PSI_cond_key key_object_loading_cond; // TODO need to initialize
12196 PSI_mutex_key key_mta_temp_table_LOCK;
12197 PSI_mutex_key key_mta_gaq_LOCK;
12198 PSI_mutex_key key_thd_timer_mutex;
12199 PSI_mutex_key key_commit_order_manager_mutex;
12200 PSI_mutex_key key_mutex_replica_worker_hash;
12201 PSI_mutex_key key_monitor_info_run_lock;
12202 PSI_mutex_key key_LOCK_delegate_connection_mutex;
12203 PSI_mutex_key key_LOCK_group_replication_connection_mutex;
12204
12205 /* clang-format off */
12206 static PSI_mutex_info all_server_mutexes[]=
12207 {
12208 { &key_LOCK_tc, "TC_LOG_MMAP::LOCK_tc", 0, 0, PSI_DOCUMENT_ME},
12209 { &key_BINLOG_LOCK_commit, "MYSQL_BIN_LOG::LOCK_commit", 0, 0, PSI_DOCUMENT_ME},
12210 { &key_BINLOG_LOCK_commit_queue, "MYSQL_BIN_LOG::LOCK_commit_queue", 0, 0, PSI_DOCUMENT_ME},
12211 { &key_BINLOG_LOCK_done, "MYSQL_BIN_LOG::LOCK_done", 0, 0, PSI_DOCUMENT_ME},
12212 { &key_BINLOG_LOCK_flush_queue, "MYSQL_BIN_LOG::LOCK_flush_queue", 0, 0, PSI_DOCUMENT_ME},
12213 { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0, 0, PSI_DOCUMENT_ME},
12214 { &key_BINLOG_LOCK_log, "MYSQL_BIN_LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
12215 { &key_BINLOG_LOCK_binlog_end_pos, "MYSQL_BIN_LOG::LOCK_binlog_end_pos", 0, 0, PSI_DOCUMENT_ME},
12216 { &key_BINLOG_LOCK_sync, "MYSQL_BIN_LOG::LOCK_sync", 0, 0, PSI_DOCUMENT_ME},
12217 { &key_BINLOG_LOCK_sync_queue, "MYSQL_BIN_LOG::LOCK_sync_queue", 0, 0, PSI_DOCUMENT_ME},
12218 { &key_BINLOG_LOCK_xids, "MYSQL_BIN_LOG::LOCK_xids", 0, 0, PSI_DOCUMENT_ME},
12219 { &key_RELAYLOG_LOCK_commit, "MYSQL_RELAY_LOG::LOCK_commit", 0, 0, PSI_DOCUMENT_ME},
12220 { &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0, 0, PSI_DOCUMENT_ME},
12221 { &key_RELAYLOG_LOCK_log, "MYSQL_RELAY_LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
12222 { &key_RELAYLOG_LOCK_log_end_pos, "MYSQL_RELAY_LOG::LOCK_log_end_pos", 0, 0, PSI_DOCUMENT_ME},
12223 { &key_RELAYLOG_LOCK_sync, "MYSQL_RELAY_LOG::LOCK_sync", 0, 0, PSI_DOCUMENT_ME},
12224 { &key_RELAYLOG_LOCK_xids, "MYSQL_RELAY_LOG::LOCK_xids", 0, 0, PSI_DOCUMENT_ME},
12225 { &key_hash_filo_lock, "hash_filo::lock", 0, 0, PSI_DOCUMENT_ME},
12226 { &Gtid_set::key_gtid_executed_free_intervals_mutex, "Gtid_set::gtid_executed::free_intervals_mutex", 0, 0, PSI_DOCUMENT_ME},
12227 { &key_LOCK_bloom_filter, "Bloom_filter", 0, 0, PSI_DOCUMENT_ME},
12228 { &key_LOCK_crypt, "LOCK_crypt", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12229 { &key_LOCK_error_log, "LOCK_error_log", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12230 { &key_LOCK_global_system_variables, "LOCK_global_system_variables", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12231 #if defined(_WIN32)
12232 { &key_LOCK_handler_count, "LOCK_handler_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12233 { &key_LOCK_global_user_client_stats,
12234 "LOCK_global_user_client_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12235 { &key_LOCK_global_table_stats,
12236 "LOCK_global_table_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12237 { &key_LOCK_global_index_stats,
12238 "LOCK_global_index_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12239 #endif
12240 { &key_LOCK_manager, "LOCK_manager", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12241 { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12242 { &key_LOCK_replica_list, "LOCK_replica_list", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12243 { &key_LOCK_sql_replica_skip_counter, "LOCK_sql_replica_skip_counter", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12244 { &key_LOCK_replica_net_timeout, "LOCK_replica_net_timeout", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12245 { &key_LOCK_replica_trans_dep_tracker, "LOCK_replica_trans_dep_tracker", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12246 { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12247 #if !defined(_WIN32)
12248 { &key_LOCK_socket_listener_active, "LOCK_socket_listener_active", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12249 { &key_LOCK_start_signal_handler, "LOCK_start_signal_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12250 #endif
12251 { &key_LOCK_status, "LOCK_status", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12252 { &key_LOCK_thd_data, "THD::LOCK_thd_data", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12253 { &key_LOCK_thd_query, "THD::LOCK_thd_query", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12254 { &key_LOCK_thd_sysvar, "THD::LOCK_thd_sysvar", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12255 { &key_LOCK_thd_protocol, "THD::LOCK_thd_protocol", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12256 { &key_LOCK_thd_security_ctx, "THD::LOCK_thd_security_ctx", 0, PSI_VOLATILITY_SESSION, "A lock to control access to a THD's security context"},
12257 { &key_LOCK_user_conn, "LOCK_user_conn", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12258 { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12259 { &key_LOCK_sql_rand, "LOCK_sql_rand", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12260 { &key_LOG_LOCK_log, "LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
12261 { &key_source_info_data_lock, "Source_info::data_lock", 0, 0, PSI_DOCUMENT_ME},
12262 { &key_source_info_run_lock, "Source_info::run_lock", 0, 0, PSI_DOCUMENT_ME},
12263 { &key_source_info_sleep_lock, "Source_info::sleep_lock", 0, 0, PSI_DOCUMENT_ME},
12264 { &key_source_info_thd_lock, "Source_info::info_thd_lock", 0, 0, PSI_DOCUMENT_ME},
12265 { &key_source_info_rotate_lock, "Source_info::rotate_lock", 0, 0, PSI_DOCUMENT_ME},
12266 { &key_mutex_replica_reporting_capability_err_lock, "Replica_reporting_capability::err_lock", 0, 0, PSI_DOCUMENT_ME},
12267 { &key_relay_log_info_data_lock, "Relay_log_info::data_lock", 0, 0, PSI_DOCUMENT_ME},
12268 { &key_relay_log_info_sleep_lock, "Relay_log_info::sleep_lock", 0, 0, PSI_DOCUMENT_ME},
12269 { &key_relay_log_info_thd_lock, "Relay_log_info::info_thd_lock", 0, 0, PSI_DOCUMENT_ME},
12270 { &key_relay_log_info_log_space_lock, "Relay_log_info::log_space_lock", 0, 0, PSI_DOCUMENT_ME},
12271 { &key_relay_log_info_run_lock, "Relay_log_info::run_lock", 0, 0, PSI_DOCUMENT_ME},
12272 { &key_mutex_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_lock", 0, 0, PSI_DOCUMENT_ME},
12273 { &key_mutex_slave_parallel_worker_count, "Relay_log_info::exit_count_lock", 0, 0, PSI_DOCUMENT_ME},
12274 { &key_mutex_slave_parallel_worker, "Worker_info::jobs_lock", 0, 0, PSI_DOCUMENT_ME},
12275 { &key_TABLE_SHARE_LOCK_ha_data, "TABLE_SHARE::LOCK_ha_data", 0, 0, PSI_DOCUMENT_ME},
12276 { &key_LOCK_error_messages, "LOCK_error_messages", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12277 { &key_LOCK_log_throttle_qni, "LOCK_log_throttle_qni", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12278 { &key_gtid_ensure_index_mutex, "Gtid_state", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12279 { &key_LOCK_query_plan, "THD::LOCK_query_plan", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12280 { &key_LOCK_cost_const, "Cost_constant_cache::LOCK_cost_const", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12281 { &key_LOCK_current_cond, "THD::LOCK_current_cond", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
12282 { &key_mta_temp_table_LOCK, "key_mta_temp_table_LOCK", 0, 0, PSI_DOCUMENT_ME},
12283 { &key_LOCK_reset_gtid_table, "LOCK_reset_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12284 { &key_LOCK_compress_gtid_table, "LOCK_compress_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12285 { &key_LOCK_collect_instance_log, "LOCK_collect_instance_log", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12286 { &key_mta_gaq_LOCK, "key_mta_gaq_LOCK", 0, 0, PSI_DOCUMENT_ME},
12287 { &key_thd_timer_mutex, "thd_timer_mutex", 0, 0, PSI_DOCUMENT_ME},
12288 { &key_commit_order_manager_mutex, "Commit_order_manager::m_mutex", 0, 0, PSI_DOCUMENT_ME},
12289 { &key_mutex_replica_worker_hash, "Relay_log_info::replica_worker_hash_lock", 0, 0, PSI_DOCUMENT_ME},
12290 { &key_LOCK_default_password_lifetime, "LOCK_default_password_lifetime", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12291 { &key_LOCK_mandatory_roles, "LOCK_mandatory_roles", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12292 { &key_LOCK_password_history, "LOCK_password_history", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12293 { &key_LOCK_password_reuse_interval, "LOCK_password_reuse_interval", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12294 { &key_LOCK_keyring_operations, "LOCK_keyring_operations", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12295 { &key_LOCK_tls_ctx_options, "LOCK_tls_ctx_options", 0, 0, "A lock to control all of the --ssl-* CTX related command line options for client server connection port"},
12296 { &key_LOCK_admin_tls_ctx_options, "LOCK_admin_tls_ctx_options", 0, 0, "A lock to control all of the --ssl-* CTX related command line options for administrative connection port"},
12297 { &key_LOCK_rotate_binlog_master_key, "LOCK_rotate_binlog_master_key", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12298 { &key_monitor_info_run_lock, "Source_IO_monitor::run_lock", 0, 0, PSI_DOCUMENT_ME},
12299 { &key_LOCK_delegate_connection_mutex, "LOCK_delegate_connection_mutex", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12300 { &key_LOCK_group_replication_connection_mutex, "LOCK_group_replication_connection_mutex", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12301 { &key_LOCK_authentication_policy, "LOCK_authentication_policy", PSI_FLAG_SINGLETON, 0, "A lock to ensure execution of CREATE USER or ALTER USER sql and SET @@global.authentication_policy variable are serialized"},
12302 { &key_LOCK_global_conn_mem_limit, "LOCK_global_conn_mem_limit", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
12303 };
12304 /* clang-format on */
12305
12306 PSI_rwlock_key key_rwlock_LOCK_logger;
12307 PSI_rwlock_key key_rwlock_channel_map_lock;
12308 PSI_rwlock_key key_rwlock_channel_lock;
12309 PSI_rwlock_key key_rwlock_receiver_sid_lock;
12310 PSI_rwlock_key key_rwlock_rpl_filter_lock;
12311 PSI_rwlock_key key_rwlock_channel_to_filter_lock;
12312 PSI_rwlock_key key_rwlock_LOCK_consistent_snapshot;
12313 PSI_rwlock_key key_rwlock_Trans_delegate_lock;
12314 PSI_rwlock_key key_rwlock_Server_state_delegate_lock;
12315 PSI_rwlock_key key_rwlock_Binlog_storage_delegate_lock;
12316 PSI_rwlock_key key_rwlock_Binlog_transmit_delegate_lock;
12317 PSI_rwlock_key key_rwlock_Binlog_relay_IO_delegate_lock;
12318 PSI_rwlock_key key_rwlock_resource_group_mgr_map_lock;
12319
12320 /* clang-format off */
12321 static PSI_rwlock_info all_server_rwlocks[]=
12322 {
12323 { &key_rwlock_Binlog_transmit_delegate_lock, "Binlog_transmit_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12324 { &key_rwlock_Binlog_relay_IO_delegate_lock, "Binlog_relay_IO_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12325 { &key_rwlock_LOCK_logger, "LOGGER::LOCK_logger", 0, 0, PSI_DOCUMENT_ME},
12326 { &key_rwlock_LOCK_sys_init_connect, "LOCK_sys_init_connect", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12327 { &key_rwlock_LOCK_sys_init_replica, "LOCK_sys_init_replica", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12328 { &key_rwlock_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12329 { &key_rwlock_global_sid_lock, "gtid_commit_rollback", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12330 { &key_rwlock_gtid_mode_lock, "gtid_mode_lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12331 { &key_rwlock_channel_map_lock, "channel_map_lock", 0, 0, PSI_DOCUMENT_ME},
12332 { &key_rwlock_channel_lock, "channel_lock", 0, 0, PSI_DOCUMENT_ME},
12333 { &key_rwlock_Trans_delegate_lock, "Trans_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12334 { &key_rwlock_Server_state_delegate_lock, "Server_state_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12335 { &key_rwlock_Binlog_storage_delegate_lock, "Binlog_storage_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12336 { &key_rwlock_receiver_sid_lock, "gtid_retrieved", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12337 { &key_rwlock_rpl_filter_lock, "rpl_filter_lock", 0, 0, PSI_DOCUMENT_ME},
12338 { &key_rwlock_channel_to_filter_lock, "channel_to_filter_lock", 0, 0, PSI_DOCUMENT_ME},
12339 { &key_rwlock_resource_group_mgr_map_lock, "Resource_group_mgr::m_map_rwlock", 0, 0, PSI_DOCUMENT_ME},
12340 #ifdef _WIN32
12341 { &key_rwlock_LOCK_named_pipe_full_access_group, "LOCK_named_pipe_full_access_group", PSI_FLAG_SINGLETON, 0,
12342 "This lock protects named pipe security attributes, preventing their "
12343 "simultaneous application and modification."},
12344 #endif // _WIN32
12345 { &key_rwlock_LOCK_consistent_snapshot, "LOCK_consistent_snapshot", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
12346 };
12347 /* clang-format on */
12348
12349 PSI_cond_key key_PAGE_cond;
12350 PSI_cond_key key_COND_active;
12351 PSI_cond_key key_COND_pool;
12352 PSI_cond_key key_COND_cache_status_changed;
12353 PSI_cond_key key_item_func_sleep_cond;
12354 PSI_cond_key key_source_info_data_cond;
12355 PSI_cond_key key_source_info_start_cond;
12356 PSI_cond_key key_source_info_stop_cond;
12357 PSI_cond_key key_source_info_sleep_cond;
12358 PSI_cond_key key_source_info_rotate_cond;
12359 PSI_cond_key key_relay_log_info_data_cond;
12360 PSI_cond_key key_relay_log_info_log_space_cond;
12361 PSI_cond_key key_relay_log_info_start_cond;
12362 PSI_cond_key key_relay_log_info_stop_cond;
12363 PSI_cond_key key_relay_log_info_sleep_cond;
12364 PSI_cond_key key_cond_slave_parallel_pend_jobs;
12365 PSI_cond_key key_cond_slave_parallel_worker;
12366 PSI_cond_key key_cond_mta_gaq;
12367 PSI_cond_key key_RELAYLOG_update_cond;
12368 PSI_cond_key key_gtid_ensure_index_cond;
12369 PSI_cond_key key_COND_thr_lock;
12370 PSI_cond_key key_commit_order_manager_cond;
12371 PSI_cond_key key_cond_slave_worker_hash;
12372 PSI_cond_key key_monitor_info_run_cond;
12373 PSI_cond_key key_COND_delegate_connection_cond_var;
12374 PSI_cond_key key_COND_group_replication_connection_cond_var;
12375
12376 /* clang-format off */
12377 static PSI_cond_info all_server_conds[]=
12378 {
12379 { &key_PAGE_cond, "PAGE::cond", 0, 0, PSI_DOCUMENT_ME},
12380 { &key_COND_active, "TC_LOG_MMAP::COND_active", 0, 0, PSI_DOCUMENT_ME},
12381 { &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0, 0, PSI_DOCUMENT_ME},
12382 { &key_BINLOG_COND_done, "MYSQL_BIN_LOG::COND_done", 0, 0, PSI_DOCUMENT_ME},
12383 { &key_BINLOG_COND_flush_queue, "MYSQL_BIN_LOG::COND_flush_queue", 0, 0, PSI_DOCUMENT_ME},
12384 { &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0, 0, PSI_DOCUMENT_ME},
12385 { &key_BINLOG_prep_xids_cond, "MYSQL_BIN_LOG::prep_xids_cond", 0, 0, PSI_DOCUMENT_ME},
12386 { &key_RELAYLOG_update_cond, "MYSQL_RELAY_LOG::update_cond", 0, 0, PSI_DOCUMENT_ME},
12387 #if defined(_WIN32)
12388 { &key_COND_handler_count, "COND_handler_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12389 #endif
12390 { &key_COND_manager, "COND_manager", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12391 { &key_COND_server_started, "COND_server_started", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12392 #if !defined(_WIN32)
12393 { &key_COND_socket_listener_active, "COND_socket_listener_active", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12394 { &key_COND_start_signal_handler, "COND_start_signal_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12395 #endif
12396 { &key_COND_thr_lock, "COND_thr_lock", 0, 0, PSI_DOCUMENT_ME},
12397 { &key_item_func_sleep_cond, "Item_func_sleep::cond", 0, 0, PSI_DOCUMENT_ME},
12398 { &key_source_info_data_cond, "Source_info::data_cond", 0, 0, PSI_DOCUMENT_ME},
12399 { &key_source_info_start_cond, "Source_info::start_cond", 0, 0, PSI_DOCUMENT_ME},
12400 { &key_source_info_stop_cond, "Source_info::stop_cond", 0, 0, PSI_DOCUMENT_ME},
12401 { &key_source_info_sleep_cond, "Source_info::sleep_cond", 0, 0, PSI_DOCUMENT_ME},
12402 { &key_source_info_rotate_cond, "Source_info::rotate_cond", 0, 0, PSI_DOCUMENT_ME},
12403 { &key_relay_log_info_data_cond, "Relay_log_info::data_cond", 0, 0, PSI_DOCUMENT_ME},
12404 { &key_relay_log_info_log_space_cond, "Relay_log_info::log_space_cond", 0, 0, PSI_DOCUMENT_ME},
12405 { &key_relay_log_info_start_cond, "Relay_log_info::start_cond", 0, 0, PSI_DOCUMENT_ME},
12406 { &key_relay_log_info_stop_cond, "Relay_log_info::stop_cond", 0, 0, PSI_DOCUMENT_ME},
12407 { &key_relay_log_info_sleep_cond, "Relay_log_info::sleep_cond", 0, 0, PSI_DOCUMENT_ME},
12408 { &key_cond_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_cond", 0, 0, PSI_DOCUMENT_ME},
12409 { &key_cond_slave_parallel_worker, "Worker_info::jobs_cond", 0, 0, PSI_DOCUMENT_ME},
12410 { &key_cond_mta_gaq, "Relay_log_info::mta_gaq_cond", 0, 0, PSI_DOCUMENT_ME},
12411 { &key_gtid_ensure_index_cond, "Gtid_state", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12412 { &key_COND_compress_gtid_table, "COND_compress_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12413 { &key_commit_order_manager_cond, "Commit_order_manager::m_workers.cond", 0, 0, PSI_DOCUMENT_ME},
12414 { &key_cond_slave_worker_hash, "Relay_log_info::replica_worker_hash_cond", 0, 0, PSI_DOCUMENT_ME},
12415 { &key_monitor_info_run_cond, "Source_IO_monitor::run_cond", 0, 0, PSI_DOCUMENT_ME},
12416 { &key_COND_delegate_connection_cond_var, "THD::COND_delegate_connection_cond_var", 0, 0, PSI_DOCUMENT_ME},
12417 { &key_COND_group_replication_connection_cond_var, "THD::COND_group_replication_connection_cond_var", 0, 0, PSI_DOCUMENT_ME}
12418 };
12419 /* clang-format on */
12420
12421 PSI_thread_key key_thread_bootstrap;
12422 PSI_thread_key key_thread_handle_manager;
12423 PSI_thread_key key_thread_one_connection;
12424 PSI_thread_key key_thread_compress_gtid_table;
12425 PSI_thread_key key_thread_parser_service;
12426 PSI_thread_key key_thread_handle_con_admin_sockets;
12427
12428 /* clang-format off */
12429 static PSI_thread_info all_server_threads[]=
12430 {
12431 #if defined (_WIN32)
12432 { &key_thread_handle_con_namedpipes, "con_named_pipes", "con_pipe", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12433 { &key_thread_handle_con_sharedmem, "con_shared_mem", "con_shm", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12434 { &key_thread_handle_con_sockets, "con_sockets", "con_sock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12435 { &key_thread_handle_shutdown_restart, "shutdown_restart", "down_up", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12436 #endif /* _WIN32 */
12437 { &key_thread_bootstrap, "bootstrap", "boot", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12438 { &key_thread_handle_manager, "manager", "handle_mgr", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12439 { &key_thread_main, "main", "main", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12440 { &key_thread_one_connection, "one_connection", "connection",
12441 PSI_FLAG_USER | PSI_FLAG_NO_SEQNUM, 0, PSI_DOCUMENT_ME},
12442 { &key_thread_signal_hand, "signal_handler", "sig_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12443 { &key_thread_compress_gtid_table, "compress_gtid_table", "gtid_zip", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12444 { &key_thread_parser_service, "parser_service", "parser_srv", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12445 { &key_thread_handle_con_admin_sockets, "admin_interface", "con_admin", PSI_FLAG_USER, 0, PSI_DOCUMENT_ME},
12446 };
12447 /* clang-format on */
12448
12449 PSI_file_key key_file_binlog;
12450 PSI_file_key key_file_binlog_index;
12451 PSI_file_key key_file_dbopt;
12452 PSI_file_key key_file_ERRMSG;
12453 PSI_file_key key_select_to_file;
12454 PSI_file_key key_file_fileparser;
12455 PSI_file_key key_file_frm;
12456 PSI_file_key key_file_load;
12457 PSI_file_key key_file_loadfile;
12458 PSI_file_key key_file_log_event_data;
12459 PSI_file_key key_file_log_event_info;
12460 PSI_file_key key_file_misc;
12461 PSI_file_key key_file_tclog;
12462 PSI_file_key key_file_trg;
12463 PSI_file_key key_file_trn;
12464 PSI_file_key key_file_init;
12465 PSI_file_key key_file_general_log;
12466 PSI_file_key key_file_slow_log;
12467 PSI_file_key key_file_relaylog;
12468 PSI_file_key key_file_relaylog_cache;
12469 PSI_file_key key_file_relaylog_index;
12470 PSI_file_key key_file_relaylog_index_cache;
12471 PSI_file_key key_file_sdi;
12472 PSI_file_key key_file_hash_join;
12473
12474 /* clang-format off */
12475 static PSI_file_info all_server_files[]=
12476 {
12477 { &key_file_binlog, "binlog", 0, 0, PSI_DOCUMENT_ME},
12478 { &key_file_binlog_cache, "binlog_cache", 0, 0, PSI_DOCUMENT_ME},
12479 { &key_file_binlog_index, "binlog_index", 0, 0, PSI_DOCUMENT_ME},
12480 { &key_file_binlog_index_cache, "binlog_index_cache", 0, 0, PSI_DOCUMENT_ME},
12481 { &key_file_relaylog, "relaylog", 0, 0, PSI_DOCUMENT_ME},
12482 { &key_file_relaylog_cache, "relaylog_cache", 0, 0, PSI_DOCUMENT_ME},
12483 { &key_file_relaylog_index, "relaylog_index", 0, 0, PSI_DOCUMENT_ME},
12484 { &key_file_relaylog_index_cache, "relaylog_index_cache", 0, 0, PSI_DOCUMENT_ME},
12485 { &key_file_io_cache, "io_cache", 0, 0, PSI_DOCUMENT_ME},
12486 { &key_file_casetest, "casetest", 0, 0, PSI_DOCUMENT_ME},
12487 { &key_file_dbopt, "dbopt", 0, 0, PSI_DOCUMENT_ME},
12488 { &key_file_ERRMSG, "ERRMSG", 0, 0, PSI_DOCUMENT_ME},
12489 { &key_select_to_file, "select_to_file", 0, 0, PSI_DOCUMENT_ME},
12490 { &key_file_fileparser, "file_parser", 0, 0, PSI_DOCUMENT_ME},
12491 { &key_file_frm, "FRM", 0, 0, PSI_DOCUMENT_ME},
12492 { &key_file_load, "load", 0, 0, PSI_DOCUMENT_ME},
12493 { &key_file_loadfile, "LOAD_FILE", 0, 0, PSI_DOCUMENT_ME},
12494 { &key_file_log_event_data, "log_event_data", 0, 0, PSI_DOCUMENT_ME},
12495 { &key_file_log_event_info, "log_event_info", 0, 0, PSI_DOCUMENT_ME},
12496 { &key_file_misc, "misc", 0, 0, PSI_DOCUMENT_ME},
12497 { &key_file_pid, "pid", 0, 0, PSI_DOCUMENT_ME},
12498 { &key_file_general_log, "query_log", 0, 0, PSI_DOCUMENT_ME},
12499 { &key_file_slow_log, "slow_log", 0, 0, PSI_DOCUMENT_ME},
12500 { &key_file_tclog, "tclog", 0, 0, PSI_DOCUMENT_ME},
12501 { &key_file_trg, "trigger_name", 0, 0, PSI_DOCUMENT_ME},
12502 { &key_file_trn, "trigger", 0, 0, PSI_DOCUMENT_ME},
12503 { &key_file_init, "init", 0, 0, PSI_DOCUMENT_ME},
12504 { &key_file_sdi, "SDI", 0, 0, PSI_DOCUMENT_ME},
12505 { &key_file_hash_join, "hash_join", 0, 0, PSI_DOCUMENT_ME}
12506 };
12507 /* clang-format on */
12508 #endif /* HAVE_PSI_INTERFACE */
12509
12510 /* clang-format off */
12511 PSI_stage_info stage_after_create= { 0, "After create", 0, PSI_DOCUMENT_ME};
12512 PSI_stage_info stage_alter_inplace_prepare= { 0, "preparing for alter table", 0, PSI_DOCUMENT_ME};
12513 PSI_stage_info stage_alter_inplace= { 0, "altering table", 0, PSI_DOCUMENT_ME};
12514 PSI_stage_info stage_alter_inplace_commit= { 0, "committing alter table to storage engine", 0, PSI_DOCUMENT_ME};
12515 PSI_stage_info stage_changing_source= { 0, "Changing replication source", 0, PSI_DOCUMENT_ME};
12516 PSI_stage_info stage_checking_source_version= { 0, "Checking source version", 0, PSI_DOCUMENT_ME};
12517 PSI_stage_info stage_checking_permissions= { 0, "checking permissions", 0, PSI_DOCUMENT_ME};
12518 PSI_stage_info stage_cleaning_up= { 0, "cleaning up", 0, PSI_DOCUMENT_ME};
12519 PSI_stage_info stage_closing_tables= { 0, "closing tables", 0, PSI_DOCUMENT_ME};
12520 PSI_stage_info stage_compressing_gtid_table= { 0, "Compressing gtid_executed table", 0, PSI_DOCUMENT_ME};
12521 PSI_stage_info stage_connecting_to_source= { 0, "Connecting to source", 0, PSI_DOCUMENT_ME};
12522 PSI_stage_info stage_converting_heap_to_ondisk= { 0, "converting HEAP to ondisk", 0, PSI_DOCUMENT_ME};
12523 PSI_stage_info stage_copy_to_tmp_table= { 0, "copy to tmp table", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
12524 PSI_stage_info stage_creating_table= { 0, "creating table", 0, PSI_DOCUMENT_ME};
12525 PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0, PSI_DOCUMENT_ME};
12526 PSI_stage_info stage_deleting_from_main_table= { 0, "deleting from main table", 0, PSI_DOCUMENT_ME};
12527 PSI_stage_info stage_deleting_from_reference_tables= { 0, "deleting from reference tables", 0, PSI_DOCUMENT_ME};
12528 PSI_stage_info stage_discard_or_import_tablespace= { 0, "discard_or_import_tablespace", 0, PSI_DOCUMENT_ME};
12529 PSI_stage_info stage_end= { 0, "end", 0, PSI_DOCUMENT_ME};
12530 PSI_stage_info stage_executing= { 0, "executing", 0, PSI_DOCUMENT_ME};
12531 PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0, PSI_DOCUMENT_ME};
12532 PSI_stage_info stage_explaining= { 0, "explaining", 0, PSI_DOCUMENT_ME};
12533 PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, "Finished reading one binlog; switching to next binlog", 0, PSI_DOCUMENT_ME};
12534 PSI_stage_info stage_flushing_relay_log_and_source_info_repository= { 0, "Flushing relay log and source info repository.", 0, PSI_DOCUMENT_ME};
12535 PSI_stage_info stage_flushing_relay_log_info_file= { 0, "Flushing relay-log info file.", 0, PSI_DOCUMENT_ME};
12536 PSI_stage_info stage_freeing_items= { 0, "freeing items", 0, PSI_DOCUMENT_ME};
12537 PSI_stage_info stage_fulltext_initialization= { 0, "FULLTEXT initialization", 0, PSI_DOCUMENT_ME};
12538 PSI_stage_info stage_init= { 0, "init", 0, PSI_DOCUMENT_ME};
12539 PSI_stage_info stage_killing_replica= { 0, "Killing replica", 0, PSI_DOCUMENT_ME};
12540 PSI_stage_info stage_logging_slow_query= { 0, "logging slow query", 0, PSI_DOCUMENT_ME};
12541 PSI_stage_info stage_making_temp_file_append_before_load_data= { 0, "Making temporary file (append) before replaying LOAD DATA INFILE", 0, PSI_DOCUMENT_ME};
12542 PSI_stage_info stage_manage_keys= { 0, "manage keys", 0, PSI_DOCUMENT_ME};
12543 PSI_stage_info stage_source_has_sent_all_binlog_to_replica= { 0, "Source has sent all binlog to replica; waiting for more updates", 0, PSI_DOCUMENT_ME};
12544 PSI_stage_info stage_opening_tables= { 0, "Opening tables", 0, PSI_DOCUMENT_ME};
12545 PSI_stage_info stage_optimizing= { 0, "optimizing", 0, PSI_DOCUMENT_ME};
12546 PSI_stage_info stage_preparing= { 0, "preparing", 0, PSI_DOCUMENT_ME};
12547 PSI_stage_info stage_purging_old_relay_logs= { 0, "Purging old relay logs", 0, PSI_DOCUMENT_ME};
12548 PSI_stage_info stage_query_end= { 0, "query end", 0, PSI_DOCUMENT_ME};
12549 PSI_stage_info stage_queueing_source_event_to_the_relay_log= { 0, "Queueing source event to the relay log", 0, PSI_DOCUMENT_ME};
12550 PSI_stage_info stage_reading_event_from_the_relay_log= { 0, "Reading event from the relay log", 0, PSI_DOCUMENT_ME};
12551 PSI_stage_info stage_registering_replica_on_source= { 0, "Registering replica on source", 0, PSI_DOCUMENT_ME};
12552 PSI_stage_info stage_removing_tmp_table= { 0, "removing tmp table", 0, PSI_DOCUMENT_ME};
12553 PSI_stage_info stage_rename= { 0, "rename", 0, PSI_DOCUMENT_ME};
12554 PSI_stage_info stage_rename_result_table= { 0, "rename result table", 0, PSI_DOCUMENT_ME};
12555 PSI_stage_info stage_requesting_binlog_dump= { 0, "Requesting binlog dump", 0, PSI_DOCUMENT_ME};
12556 PSI_stage_info stage_searching_rows_for_update= { 0, "Searching rows for update", 0, PSI_DOCUMENT_ME};
12557 PSI_stage_info stage_sending_binlog_event_to_replica= { 0, "Sending binlog event to replica", 0, PSI_DOCUMENT_ME};
12558 PSI_stage_info stage_setup= { 0, "setup", 0, PSI_DOCUMENT_ME};
12559 PSI_stage_info stage_replica_has_read_all_relay_log= { 0, "Replica has read all relay log; waiting for more updates", 0, PSI_DOCUMENT_ME};
12560 PSI_stage_info stage_replica_reconnecting_after_failed_binlog_dump_request{ 0, "Reconnecting after a failed binlog dump request", 0, PSI_DOCUMENT_ME};
12561 PSI_stage_info stage_replica_reconnecting_after_failed_event_read{ 0, "Reconnecting after a failed source event read", 0, PSI_DOCUMENT_ME};
12562 PSI_stage_info stage_replica_reconnecting_after_failed_registration_on_source{ 0, "Reconnecting after a failed registration on source", 0, PSI_DOCUMENT_ME};
12563 PSI_stage_info stage_replica_waiting_event_from_coordinator= { 0, "Waiting for an event from Coordinator", 0, PSI_DOCUMENT_ME};
12564 PSI_stage_info stage_replica_waiting_for_workers_to_process_queue= { 0, "Waiting for replica workers to process their queues", 0, PSI_DOCUMENT_ME};
12565 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_binlog_dump_request{ 0, "Waiting to reconnect after a failed binlog dump request", 0, PSI_DOCUMENT_ME};
12566 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_event_read{ 0, "Waiting to reconnect after a failed source event read", 0, PSI_DOCUMENT_ME};
12567 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_registration_on_source{ 0, "Waiting to reconnect after a failed registration on source", 0, PSI_DOCUMENT_ME};
12568 PSI_stage_info stage_replica_waiting_worker_queue= { 0, "Waiting for Replica Worker queue", 0, PSI_DOCUMENT_ME};
12569 PSI_stage_info stage_replica_waiting_worker_to_free_events= { 0, "Waiting for Replica Workers to free pending events", 0, PSI_DOCUMENT_ME};
12570 PSI_stage_info stage_replica_waiting_worker_to_release_partition= { 0, "Waiting for Replica Worker to release partition", 0, PSI_DOCUMENT_ME};
12571 PSI_stage_info stage_replica_waiting_workers_to_exit= { 0, "Waiting for workers to exit", 0, PSI_DOCUMENT_ME};
12572 PSI_stage_info stage_rpl_apply_row_evt_write= { 0, "Applying batch of row changes (write)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
12573 PSI_stage_info stage_rpl_apply_row_evt_update= { 0, "Applying batch of row changes (update)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
12574 PSI_stage_info stage_rpl_apply_row_evt_delete= { 0, "Applying batch of row changes (delete)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
12575 PSI_stage_info stage_statistics= { 0, "statistics", 0, PSI_DOCUMENT_ME};
12576 PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until SOURCE_DELAY seconds after source executed event", 0, PSI_DOCUMENT_ME};
12577 PSI_stage_info stage_system_lock= { 0, "System lock", 0, PSI_DOCUMENT_ME};
12578 PSI_stage_info stage_update= { 0, "update", 0, PSI_DOCUMENT_ME};
12579 PSI_stage_info stage_updating= { 0, "updating", 0, PSI_DOCUMENT_ME};
12580 PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0, PSI_DOCUMENT_ME};
12581 PSI_stage_info stage_updating_reference_tables= { 0, "updating reference tables", 0, PSI_DOCUMENT_ME};
12582 PSI_stage_info stage_user_sleep= { 0, "User sleep", 0, PSI_DOCUMENT_ME};
12583 PSI_stage_info stage_verifying_table= { 0, "verifying table", 0, PSI_DOCUMENT_ME};
12584 PSI_stage_info stage_waiting_for_gtid_to_be_committed= { 0, "Waiting for GTID to be committed", 0, PSI_DOCUMENT_ME};
12585 PSI_stage_info stage_waiting_for_handler_commit= { 0, "waiting for handler commit", 0, PSI_DOCUMENT_ME};
12586 PSI_stage_info stage_waiting_for_source_to_send_event= { 0, "Waiting for source to send event", 0, PSI_DOCUMENT_ME};
12587 PSI_stage_info stage_waiting_for_source_update= { 0, "Waiting for source update", 0, PSI_DOCUMENT_ME};
12588 PSI_stage_info stage_waiting_for_relay_log_space= { 0, "Waiting for the replica SQL thread to free relay log space", 0, PSI_DOCUMENT_ME};
12589 PSI_stage_info stage_waiting_for_replica_mutex_on_exit= { 0, "Waiting for replica mutex on exit", 0, PSI_DOCUMENT_ME};
12590 PSI_stage_info stage_waiting_for_replica_thread_to_start= { 0, "Waiting for replica thread to start", 0, PSI_DOCUMENT_ME};
12591 PSI_stage_info stage_waiting_for_table_flush= { 0, "Waiting for table flush", 0, PSI_DOCUMENT_ME};
12592 PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, "Waiting for the next event in relay log", 0, PSI_DOCUMENT_ME};
12593 PSI_stage_info stage_waiting_for_the_replica_thread_to_advance_position= { 0, "Waiting for the replica SQL thread to advance position", 0, PSI_DOCUMENT_ME};
12594 PSI_stage_info stage_waiting_to_finalize_termination= { 0, "Waiting to finalize termination", 0, PSI_DOCUMENT_ME};
12595 PSI_stage_info stage_worker_waiting_for_its_turn_to_commit= { 0, "Waiting for preceding transaction to commit", 0, PSI_DOCUMENT_ME};
12596 PSI_stage_info stage_worker_waiting_for_commit_parent= { 0, "Waiting for dependent transaction to commit", 0, PSI_DOCUMENT_ME};
12597 PSI_stage_info stage_suspending= { 0, "Suspending", 0, PSI_DOCUMENT_ME};
12598 PSI_stage_info stage_starting= { 0, "starting", 0, PSI_DOCUMENT_ME};
12599 PSI_stage_info stage_waiting_for_no_channel_reference= { 0, "Waiting for no channel reference.", 0, PSI_DOCUMENT_ME};
12600 PSI_stage_info stage_hook_begin_trans= { 0, "Executing hook on transaction begin.", 0, PSI_DOCUMENT_ME};
12601 PSI_stage_info stage_binlog_transaction_compress= { 0, "Compressing transaction changes.", 0, PSI_DOCUMENT_ME};
12602 PSI_stage_info stage_binlog_transaction_decompress= { 0, "Decompressing transaction changes.", 0, PSI_DOCUMENT_ME};
12603 PSI_stage_info stage_rpl_failover_fetching_source_member_details= { 0, "Fetching source member details from connected source", 0, PSI_DOCUMENT_ME};
12604 PSI_stage_info stage_rpl_failover_updating_source_member_details= { 0, "Updating fetched source member details on receiver", 0, PSI_DOCUMENT_ME};
12605 PSI_stage_info stage_rpl_failover_wait_before_next_fetch= { 0, "Wait before trying to fetch next membership changes from source", 0, PSI_DOCUMENT_ME};
12606 PSI_stage_info stage_communication_delegation= { 0, "Connection delegated to Group Replication", 0, PSI_DOCUMENT_ME};
12607 PSI_stage_info stage_restoring_secondary_keys= { 0, "restoring secondary keys", 0, PSI_DOCUMENT_ME};
12608 /* clang-format on */
12609
12610 extern PSI_stage_info stage_waiting_for_disk_space;
12611
12612 #ifdef HAVE_PSI_INTERFACE
12613
12614 PSI_stage_info *all_server_stages[] = {
12615 &stage_after_create,
12616 &stage_alter_inplace_prepare,
12617 &stage_alter_inplace,
12618 &stage_alter_inplace_commit,
12619 &stage_changing_source,
12620 &stage_checking_source_version,
12621 &stage_checking_permissions,
12622 &stage_cleaning_up,
12623 &stage_closing_tables,
12624 &stage_compressing_gtid_table,
12625 &stage_connecting_to_source,
12626 &stage_converting_heap_to_ondisk,
12627 &stage_copy_to_tmp_table,
12628 &stage_creating_table,
12629 &stage_creating_tmp_table,
12630 &stage_deleting_from_main_table,
12631 &stage_deleting_from_reference_tables,
12632 &stage_discard_or_import_tablespace,
12633 &stage_end,
12634 &stage_executing,
12635 &stage_execution_of_init_command,
12636 &stage_explaining,
12637 &stage_finished_reading_one_binlog_switching_to_next_binlog,
12638 &stage_flushing_relay_log_and_source_info_repository,
12639 &stage_flushing_relay_log_info_file,
12640 &stage_freeing_items,
12641 &stage_fulltext_initialization,
12642 &stage_init,
12643 &stage_killing_replica,
12644 &stage_logging_slow_query,
12645 &stage_making_temp_file_append_before_load_data,
12646 &stage_manage_keys,
12647 &stage_source_has_sent_all_binlog_to_replica,
12648 &stage_opening_tables,
12649 &stage_optimizing,
12650 &stage_preparing,
12651 &stage_purging_old_relay_logs,
12652 &stage_query_end,
12653 &stage_queueing_source_event_to_the_relay_log,
12654 &stage_reading_event_from_the_relay_log,
12655 &stage_registering_replica_on_source,
12656 &stage_removing_tmp_table,
12657 &stage_rename,
12658 &stage_rename_result_table,
12659 &stage_requesting_binlog_dump,
12660 &stage_searching_rows_for_update,
12661 &stage_sending_binlog_event_to_replica,
12662 &stage_setup,
12663 &stage_replica_has_read_all_relay_log,
12664 &stage_replica_reconnecting_after_failed_binlog_dump_request,
12665 &stage_replica_reconnecting_after_failed_event_read,
12666 &stage_replica_reconnecting_after_failed_registration_on_source,
12667 &stage_replica_waiting_event_from_coordinator,
12668 &stage_replica_waiting_for_workers_to_process_queue,
12669 &stage_replica_waiting_worker_queue,
12670 &stage_replica_waiting_to_reconnect_after_failed_binlog_dump_request,
12671 &stage_replica_waiting_to_reconnect_after_failed_event_read,
12672 &stage_replica_waiting_to_reconnect_after_failed_registration_on_source,
12673 &stage_replica_waiting_worker_to_free_events,
12674 &stage_replica_waiting_worker_to_release_partition,
12675 &stage_replica_waiting_workers_to_exit,
12676 &stage_rpl_apply_row_evt_write,
12677 &stage_rpl_apply_row_evt_update,
12678 &stage_rpl_apply_row_evt_delete,
12679 &stage_sql_thd_waiting_until_delay,
12680 &stage_statistics,
12681 &stage_system_lock,
12682 &stage_update,
12683 &stage_updating,
12684 &stage_updating_main_table,
12685 &stage_updating_reference_tables,
12686 &stage_user_sleep,
12687 &stage_verifying_table,
12688 &stage_waiting_for_gtid_to_be_committed,
12689 &stage_waiting_for_handler_commit,
12690 &stage_waiting_for_source_to_send_event,
12691 &stage_waiting_for_source_update,
12692 &stage_waiting_for_relay_log_space,
12693 &stage_waiting_for_replica_mutex_on_exit,
12694 &stage_waiting_for_replica_thread_to_start,
12695 &stage_waiting_for_table_flush,
12696 &stage_waiting_for_the_next_event_in_relay_log,
12697 &stage_waiting_for_the_replica_thread_to_advance_position,
12698 &stage_waiting_to_finalize_termination,
12699 &stage_worker_waiting_for_its_turn_to_commit,
12700 &stage_worker_waiting_for_commit_parent,
12701 &stage_suspending,
12702 &stage_starting,
12703 &stage_waiting_for_no_channel_reference,
12704 &stage_hook_begin_trans,
12705 &stage_waiting_for_disk_space,
12706 &stage_binlog_transaction_compress,
12707 &stage_binlog_transaction_decompress,
12708 &stage_rpl_failover_fetching_source_member_details,
12709 &stage_rpl_failover_updating_source_member_details,
12710 &stage_rpl_failover_wait_before_next_fetch,
12711 &stage_communication_delegation,
12712 &stage_restoring_secondary_keys};
12713
12714 PSI_socket_key key_socket_tcpip;
12715 PSI_socket_key key_socket_unix;
12716 PSI_socket_key key_socket_client_connection;
12717
12718 /* clang-format off */
12719 static PSI_socket_info all_server_sockets[]=
12720 {
12721 { &key_socket_tcpip, "server_tcpip_socket", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12722 { &key_socket_unix, "server_unix_socket", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
12723 { &key_socket_client_connection, "client_connection", PSI_FLAG_USER, 0, PSI_DOCUMENT_ME}
12724 };
12725 /* clang-format on */
12726
12727 /* TODO: find a good header */
12728 void init_client_psi_keys(void);
12729
12730 /**
12731 Initialise all the performance schema instrumentation points
12732 used by the server.
12733 */
12734 12109 static void init_server_psi_keys(void) {
12735 12109 const char *category = "sql";
12736 int count;
12737
12738 12109 count = static_cast<int>(array_elements(all_server_mutexes));
12739 12109 mysql_mutex_register(category, all_server_mutexes, count);
12740
12741 12109 count = static_cast<int>(array_elements(all_server_rwlocks));
12742 12109 mysql_rwlock_register(category, all_server_rwlocks, count);
12743
12744 12109 count = static_cast<int>(array_elements(all_server_conds));
12745 12109 mysql_cond_register(category, all_server_conds, count);
12746
12747 12109 count = static_cast<int>(array_elements(all_server_threads));
12748 12109 mysql_thread_register(category, all_server_threads, count);
12749
12750 12109 count = static_cast<int>(array_elements(all_server_files));
12751 12109 mysql_file_register(category, all_server_files, count);
12752
12753 12109 count = static_cast<int>(array_elements(all_server_stages));
12754 12109 mysql_stage_register(category, all_server_stages, count);
12755
12756 12109 count = static_cast<int>(array_elements(all_server_sockets));
12757 12109 mysql_socket_register(category, all_server_sockets, count);
12758
12759 12109 register_server_memory_keys();
12760
12761 #ifdef HAVE_PSI_STATEMENT_INTERFACE
12762 12109 init_sql_statement_info();
12763
12764 /* Register [0 .. SQLCOM_CLONE - 1] as "statement/sql/..." */
12765 12109 count = (int)SQLCOM_CLONE;
12766 12109 mysql_statement_register(category, sql_statement_info, count);
12767
12768 /* Exclude SQLCOM_CLONE as it mutates and is registered as abstract. */
12769 12109 count = (int)SQLCOM_END - (int)SQLCOM_CLONE;
12770 12109 mysql_statement_register(category, &sql_statement_info[(int)SQLCOM_CLONE + 1],
12771 count);
12772 12109 category = "abstract";
12773 12109 mysql_statement_register(category, &sql_statement_info[(int)SQLCOM_CLONE], 1);
12774
12775 12109 init_sp_psi_keys();
12776
12777 12109 init_scheduler_psi_keys();
12778
12779 12109 category = "com";
12780 12109 init_com_statement_info();
12781
12782 /*
12783 Register [0 .. COM_QUERY - 1] as "statement/com/..."
12784 */
12785 12109 count = (int)COM_QUERY;
12786 12109 mysql_statement_register(category, com_statement_info, count);
12787
12788 /* Exclude COM_CLONE as it would mutate */
12789 12109 count = (int)COM_CLONE - (int)COM_QUERY - 1;
12790 12109 mysql_statement_register(category, &com_statement_info[(int)COM_QUERY + 1],
12791 count);
12792 /*
12793 Register [COM_CLONE + 1 .. COM_END] as "statement/com/..."
12794 */
12795 12109 count = (int)COM_END - (int)COM_CLONE;
12796 12109 mysql_statement_register(category, &com_statement_info[(int)COM_CLONE + 1],
12797 count);
12798 12109 category = "abstract";
12799 /*
12800 Register [COM_QUERY] as "statement/abstract/com_query"
12801 */
12802 12109 mysql_statement_register(category, &com_statement_info[(int)COM_QUERY], 1);
12803 12109 mysql_statement_register(category, &com_statement_info[(int)COM_CLONE], 1);
12804
12805 /*
12806 When a new packet is received,
12807 it is instrumented as "statement/abstract/new_packet".
12808 Based on the packet type found, it later mutates to the
12809 proper narrow type, for example
12810 "statement/abstract/query" or "statement/com/ping".
12811 In cases of "statement/abstract/query", SQL queries are given to
12812 the parser, which mutates the statement type to an even more
12813 narrow classification, for example "statement/sql/select".
12814 */
12815 12109 stmt_info_new_packet.m_key = 0;
12816 12109 stmt_info_new_packet.m_name = "new_packet";
12817 12109 stmt_info_new_packet.m_flags = PSI_FLAG_MUTABLE;
12818 12109 stmt_info_new_packet.m_documentation =
12819 "New packet just received from the network. "
12820 "At this point, the real command type is unknown, "
12821 "the type will be refined after reading the packet header.";
12822 12109 mysql_statement_register(category, &stmt_info_new_packet, 1);
12823
12824 /*
12825 Statements processed from the relay log are initially instrumented as
12826 "statement/abstract/relay_log". The parser will mutate the statement type to
12827 a more specific classification, for example "statement/sql/insert".
12828 */
12829 12109 stmt_info_rpl.m_key = 0;
12830 12109 stmt_info_rpl.m_name = "relay_log";
12831 12109 stmt_info_rpl.m_flags = PSI_FLAG_MUTABLE;
12832 12109 stmt_info_rpl.m_documentation =
12833 "New event just read from the relay log. "
12834 "At this point, the real statement type is unknown, "
12835 "the type will be refined after parsing the event.";
12836 12109 mysql_statement_register(category, &stmt_info_rpl, 1);
12837 #endif
12838
12839 /* Common client and server code. */
12840 12109 init_client_psi_keys();
12841 /* Vio */
12842 12109 init_vio_psi_keys();
12843 /* TLS interfaces */
12844 12109 init_tls_psi_keys();
12845 12109 }
12846 #endif /* HAVE_PSI_INTERFACE */
12847
12848 17307 bool do_create_native_table_for_pfs(THD *thd, const Plugin_table *t) {
12849 17307 const char *schema_name = t->get_schema_name();
12850 17307 const char *table_name = t->get_name();
12851 17307 MDL_request table_request;
12852
1/2
✓ Branch 0 taken 17307 times.
✗ Branch 1 not taken.
17307 MDL_REQUEST_INIT(&table_request, MDL_key::TABLE, schema_name, table_name,
12853 MDL_EXCLUSIVE, MDL_TRANSACTION);
12854
12855
2/4
✓ Branch 0 taken 17307 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17307 times.
17307 if (thd->mdl_context.acquire_lock(&table_request,
12856 thd->variables.lock_wait_timeout)) {
12857 /* Error, failed to get MDL lock. */
12858 return true;
12859 }
12860
12861
1/2
✓ Branch 0 taken 17307 times.
✗ Branch 1 not taken.
17307 tdc_remove_table(thd, TDC_RT_REMOVE_ALL, schema_name, table_name, false);
12862
12863
2/4
✓ Branch 0 taken 17307 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17307 times.
17307 if (dd::create_native_table(thd, t)) {
12864 /* Error, failed to create DD table. */
12865 return true;
12866 }
12867
12868 17307 return false;
12869 }
12870
12871 17308 bool create_native_table_for_pfs(const Plugin_table *t) {
12872 /* If InnoDB is not initialized yet, return error */
12873
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17307 times.
17308 if (!is_builtin_and_core_se_initialized()) return true;
12874
12875 17307 THD *thd = current_thd;
12876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17307 times.
17307 assert(thd);
12877 17307 return do_create_native_table_for_pfs(thd, t);
12878 }
12879
12880 11872 static bool do_drop_native_table_for_pfs(THD *thd, const char *schema_name,
12881 const char *table_name) {
12882 11872 MDL_request table_request;
12883
1/2
✓ Branch 0 taken 11872 times.
✗ Branch 1 not taken.
11872 MDL_REQUEST_INIT(&table_request, MDL_key::TABLE, schema_name, table_name,
12884 MDL_EXCLUSIVE, MDL_TRANSACTION);
12885
12886
3/4
✓ Branch 0 taken 11872 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11871 times.
11872 if (thd->mdl_context.acquire_lock(&table_request,
12887 thd->variables.lock_wait_timeout)) {
12888 /* Error, failed to get MDL lock. */
12889 1 return true;
12890 }
12891
12892
1/2
✓ Branch 0 taken 11871 times.
✗ Branch 1 not taken.
11871 tdc_remove_table(thd, TDC_RT_REMOVE_ALL, schema_name, table_name, false);
12893
12894
2/4
✓ Branch 0 taken 11871 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11871 times.
11871 if (dd::drop_native_table(thd, schema_name, table_name)) {
12895 /* Error, failed to destroy DD table. */
12896 return true;
12897 }
12898
12899 11871 return false;
12900 }
12901
12902 27118 bool drop_native_table_for_pfs(const char *schema_name,
12903 const char *table_name) {
12904 /* If server is shutting down, by the time control reaches here, DD would have
12905 * already been shut down. Therefore return success and tables won't be
12906 * deleted and would be available at next server start.
12907 */
12908
2/2
✓ Branch 0 taken 15160 times.
✓ Branch 1 taken 11958 times.
27118 if (get_server_state() == SERVER_SHUTTING_DOWN) {
12909 15160 return false;
12910 }
12911
12912 /* During bootstrap error cleanup, we don't have THD. */
12913 11958 THD *thd = current_thd;
12914
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 11872 times.
11958 if (thd == nullptr) {
12915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
86 assert(get_server_state() == SERVER_BOOTING);
12916 86 return false;
12917 }
12918 11872 return do_drop_native_table_for_pfs(thd, schema_name, table_name);
12919 }
12920
12921 #ifdef _WIN32
12922 // update_named_pipe_full_access_group returns false on success, true on failure
12923 bool update_named_pipe_full_access_group(const char *new_group_name) {
12924 if (named_pipe_acceptor) {
12925 return named_pipe_listener->update_named_pipe_full_access_group(
12926 new_group_name);
12927 }
12928 return true;
12929 }
12930
12931 #endif // _WIN32
12932
12933 /**
12934 Get status partial_revokes on server
12935
12936 @return a bool indicating partial_revokes status of the server.
12937 @retval true Parital revokes is ON
12938 @retval flase Partial revokes is OFF
12939 */
12940 538726 bool mysqld_partial_revokes() {
12941 538726 return partial_revokes.load(std::memory_order_relaxed);
12942 }
12943
12944 /**
12945 Set partial_revokes with a given value
12946
12947 @param value true or false indicating the status of partial revokes
12948 turned ON/OFF on server.
12949 */
12950 12271 void set_mysqld_partial_revokes(bool value) {
12951 12271 partial_revokes.store(value, std::memory_order_relaxed);
12952 12271 }
12953
12954 /**
12955 If there exists at least one restrictions on any user,
12956 then update global variables which track the partial_revokes.
12957
12958 @param thd THD handle
12959
12960 @return a bool indicating partial_revokes status of the server.
12961 @retval true Parital revokes exists; updated the global variables.
12962 @retval false Partial revokes does not exist.
12963 */
12964 15692 bool check_and_update_partial_revokes_sysvar(THD *thd) {
12965
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 15630 times.
15692 if (is_partial_revoke_exists(thd)) {
12966 62 MUTEX_LOCK(lock, &LOCK_partial_revokes);
12967
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 set_mysqld_partial_revokes(true);
12968 62 opt_partial_revokes = true;
12969 62 return true;
12970 62 }
12971 15630 return false;
12972 }
12973